From 43f0c3b41aac495b8c0d638bc86bc35196b150be Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 4 Feb 2024 20:55:35 +0100 Subject: [PATCH] ui: move event from temporary object to parent --- src/renderer/ui/ui-window-library-folder.js | 26 ---------------- src/renderer/ui/ui-window-library.js | 33 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/renderer/ui/ui-window-library-folder.js b/src/renderer/ui/ui-window-library-folder.js index beb31bc..d82cf00 100644 --- a/src/renderer/ui/ui-window-library-folder.js +++ b/src/renderer/ui/ui-window-library-folder.js @@ -99,32 +99,6 @@ export default class UIWindowLibraryFolder extends HTMLElement { if (e.id) this.dom[e.id] = this.shadow.getElementById(e.id) } - macaco.events.register('update-statistics-folder', (ev, counts) => { - const real = this.cards.length > 0 ? this.cards.length : '' - const filtered = counts[this.path] ? counts[this.path] : 0 - - if (filtered <= 0 || filtered === real) { - this.dom.count.innerHTML = `${real}` - } else { - this.dom.count.innerHTML = `${real} [${filtered}]` - } - }) - - macaco.events.register('update-collection-folder', (ev, folder) => { - if (folder === this.path) { - this.dom.folder.classList.add('active') - } else { - this.dom.folder.classList.remove('active') - } - - // detect recent change - if (macaco.collection.diff.includes(this.path)) { - this.dom.folder.classList.add('recent') - } else { - this.dom.folder.classList.remove('recent') - } - }) - this.dom.folder.onclick = (ev) => { // set view to this path macaco.events.invoke('set-collection-folder', this.path) diff --git a/src/renderer/ui/ui-window-library.js b/src/renderer/ui/ui-window-library.js index 8bca3ce..f7a1c76 100644 --- a/src/renderer/ui/ui-window-library.js +++ b/src/renderer/ui/ui-window-library.js @@ -56,6 +56,7 @@ export default class UIWindowLibrary extends HTMLElement { ` dom = {} + folders = [] constructor () { super() @@ -93,8 +94,39 @@ export default class UIWindowLibrary extends HTMLElement { } } + macaco.events.register('update-statistics-folder', (ev, counts) => { + for (const element of this.folders) { + const real = element.cards.length > 0 ? element.cards.length : '' + const filtered = counts[element.path] ? counts[element.path] : 0 + + if (filtered <= 0 || filtered === real) { + element.dom.count.innerHTML = `${real}` + } else { + element.dom.count.innerHTML = `${real} [${filtered}]` + } + } + }) + + macaco.events.register('update-collection-folder', (ev, folder) => { + for (const element of this.folders) { + if (folder === element.path) { + element.dom.folder.classList.add('active') + } else { + element.dom.folder.classList.remove('active') + } + + // detect recent change + if (macaco.collection.diff.includes(element.path)) { + element.dom.folder.classList.add('recent') + } else { + element.dom.folder.classList.remove('recent') + } + } + }) + macaco.events.register('update-collection-contents', (ev, contents) => { this.dom.folders.innerHTML = '' + this.folders = [] this.dom['container-box'].style.display = 'block' @@ -103,6 +135,7 @@ export default class UIWindowLibrary extends HTMLElement { element.cards = cards element.path = path this.dom.folders.appendChild(element) + this.folders.push(element) } }) }