Skip to content

Commit

Permalink
ui: show filter result next to folder count
Browse files Browse the repository at this point in the history
  • Loading branch information
shagu committed Jan 22, 2024
1 parent ff2911b commit 6077ce9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/renderer/macaco.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,23 @@ macaco.events.register('set-statistics-contents', (ev, contents) => {
macaco.events.invoke('update-statistics-contents', statistics)
})

macaco.events.register('set-statistics-folder', (ev, view) => {
const folders = {}

for (const [folder, files] of Object.entries(macaco.collection.contents)) {
folders[folder] = macaco.filter.view(files).length
}

macaco.events.invoke('update-statistics-folder', folders)
})

/* bind events to setters: collection updates */
macaco.events.bind('update-collection-folder', 'set-collection-view')
macaco.events.bind('update-filter', 'set-collection-view')
macaco.events.bind('update-combine', 'set-collection-view')

/* bind events to setters: statistic updates */
macaco.events.bind('update-filter', 'set-statistics-folder')
macaco.events.bind('update-collection-contents', 'set-statistics-contents')
macaco.events.bind('update-collection-view', 'set-statistics-view')
macaco.events.bind('update-collection-selection', 'set-statistics-selection')
Expand Down
15 changes: 15 additions & 0 deletions src/renderer/ui/ui-window-library-folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export default class UIWindowLibraryFolder extends HTMLElement {
pointer-events: none;
}
#count b {
color: var(--font-light);
}
:host {
}
`
Expand All @@ -95,6 +99,17 @@ 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')
Expand Down

0 comments on commit 6077ce9

Please sign in to comment.