From 5b175ac2bbc01a5c1842fb29334c7a69d34ed098 Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Sat, 14 Oct 2017 03:32:59 +0200 Subject: [PATCH] Fixed a minor UI bug --- res/css/_content.sass | 4 +- res/css/search.css | 4 +- res/js/component/app.js | 91 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 res/js/component/app.js diff --git a/res/css/_content.sass b/res/css/_content.sass index 3a54a1d..8e3fbe7 100644 --- a/res/css/_content.sass +++ b/res/css/_content.sass @@ -177,8 +177,8 @@ &:before content: "" display: inline-block - height: 20px - width: 20px + height: 24px + width: 24px background-image: url(../icons/dots-horizontal.svg) background-size: cover vertical-align: top diff --git a/res/css/search.css b/res/css/search.css index 24ee914..7101bcc 100644 --- a/res/css/search.css +++ b/res/css/search.css @@ -550,8 +550,8 @@ body { .results .buffer .container > .inline-button:before { content: ""; display: inline-block; - height: 20px; - width: 20px; + height: 24px; + width: 24px; background-image: url(../icons/dots-horizontal.svg); background-size: cover; vertical-align: top; diff --git a/res/js/component/app.js b/res/js/component/app.js new file mode 100644 index 0000000..60a3597 --- /dev/null +++ b/res/js/component/app.js @@ -0,0 +1,91 @@ +const statehandler = new StateHandler(); + +class App { + constructor() { + this.navigation = new Navigation(); + this.buffers = []; + this.loadingQuery = 0; + this.render(); + this.navigation.addEventListener('search', query => { + this.search(query); + }); + statehandler.addEventListener('update', query => { + this.search(query); + }); + statehandler.init(); + } + + render() { + this.elem = function () { + var $$a = document.createElement('div'); + $$a.appendChildren(this.navigation.elem); + $$a.appendChildren(this.resultContainer = function () { + var $$d = document.createElement('div'); + $$d.setAttribute('class', 'results'); + return $$d; + }.call(this)); + return $$a; + }.call(this); + this.buffers.forEach(buffer => this.insert(buffer)); + } + + search(query, sender, buffer, network, before, since) { + this.clear(); + this.navigation.input.blur(); + this.navigation.historyView.resetNavigation(); + this.navigation.historyView.add(new HistoryElement(query)); + this.navigation.input.value = query; + statehandler.replace(query, sender, buffer, network, before, since); + if (query.trim() === '') + return; + this.loadingQuery++; + const queryId = this.loadingQuery; + load('web/search/', statehandler.parse()).then(result => { + if (this.loadingQuery !== queryId) + return; + this.buffers = result.map(buffer => { + return new Buffer(buffer.bufferid, buffer.buffername, buffer.networkname, buffer.hasmore, buffer.messages.map(msg => { + return new Context(new Message(msg.messageid, msg.time, msg.sender, msg.message)); + })); + }); + this.buffers.forEach(buffer => this.insert(buffer)); + }); + } + + clear() { + while (this.buffers.length) { + const buffer = this.buffers.pop(); + this.resultContainer.removeChild(buffer.elem); + } + } + + clearAll() { + this.clear(); + this.navigation.historyView.clear(); + statehandler.clear(); + } + + insert(buffer) { + this.resultContainer.appendChild(buffer.elem); + buffer.addEventListener('loadMore', () => this.bufferLoadMore(buffer)); + } + + bufferLoadMore(buffer) { + if (buffer.loading) + return; + buffer.setLoading(true); + const offset = buffer.count(); + console.log(offset); + load('web/searchbuffer/', statehandler.parse({ + buffer: buffer.id, + offset: offset + })).then(result => { + buffer.load(result); + buffer.setLoading(false); + }); + } +} + +moment.locale(navigator.languages || navigator.language); +const app = new App(); +document.body.insertBefore(app.elem, document.body.firstChild); \ No newline at end of file -- GitLab