Skip to content

Commit

Permalink
ui: move event from temporary object to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
shagu committed Feb 4, 2024
1 parent 3c644a2 commit 43f0c3b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
26 changes: 0 additions & 26 deletions src/renderer/ui/ui-window-library-folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} [<b>${filtered}</b>]`
}
})

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)
Expand Down
33 changes: 33 additions & 0 deletions src/renderer/ui/ui-window-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class UIWindowLibrary extends HTMLElement {
`

dom = {}
folders = []

constructor () {
super()
Expand Down Expand Up @@ -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} [<b>${filtered}</b>]`
}
}
})

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'

Expand All @@ -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)
}
})
}
Expand Down

0 comments on commit 43f0c3b

Please sign in to comment.