From b20943cfd273bb180f6f04203768ee62a960da6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Wed, 25 Feb 2026 23:50:31 +0100 Subject: [PATCH] WIP search --- static/js/dns.mjs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/static/js/dns.mjs b/static/js/dns.mjs index 32b77c8..332df24 100644 --- a/static/js/dns.mjs +++ b/static/js/dns.mjs @@ -153,11 +153,31 @@ export class Application { for (const folder of folders) this.recordsTree.append(folder.render()) + this.removeEmptyFolders() + // Subscribe to settings update since the elements they will change // exists now. _mbus.subscribe('settings_updated', event => this.handlerSettingsUpdated(event.detail)) this.setBoxedFolders(this.settings.get('boxed_folders')) + }// }}} + removeEmptyFolders(folder) {// {{{ + if (folder === undefined) + folder = this.topFolder + folder.subfolders.forEach((folder, _label) => { + this.removeEmptyFolders(folder) + }) + + // This is a leaf folder in the tree. + // It has to be removed from the parent as well, since that could be up for + // removal as well, all the way up the chain. + if (folder.subfolders.size === 0 && folder.records.length === 0) { + if (folder.parentFolder) { + folder.parentFolder.subfolders.delete(folder.labels()[0]) + } + + folder.div?.remove() + } }// }}} handlerKeys(event) {// {{{ let handled = true @@ -175,6 +195,10 @@ export class Application { new RecordDialog(new Record()).show() break + case 'f': + this.searchField.focus() + break + default: handled = false } @@ -195,13 +219,13 @@ export class Application { else document.body.classList.remove('boxed-folders') }// }}} - search() { + search() {// {{{ this.searchFor = this.searchField.value.trim().toLowerCase() this.cleanFolders() this.renderFolders() this.render() - } + }// }}} } class Folder {