From: Scott Worley Date: Fri, 20 Oct 2023 21:39:28 +0000 (-0700) Subject: TagFilter type X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/e0c49063e71dd24fce0f57a5e9ad1287b8073341?hp=06c452120f001ffee11ae5b80263fc1ed4fea481 TagFilter type --- diff --git a/vopamoi.ts b/vopamoi.ts index 1d357bd..926a1f0 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -310,6 +310,11 @@ enum CommitOrAbort { Abort, } +interface TagFilter { + description: string; + include: (task: Element) => boolean; +} + function BrowserUI() { const viewColors: { [key: string]: string } = { all: "Gold", @@ -320,7 +325,7 @@ function BrowserUI() { todo: "White", waiting: "MediumOrchid", }; - var currentTagFilter: string | null = null; + var currentTagFilter: TagFilter | null = null; var currentViewState = "todo"; var taskFocusedBeforeJumpingToInput: HTMLElement | null = null; var lastTagNameEntered = ""; @@ -611,14 +616,14 @@ function BrowserUI() { return ui.setState(createTimestamp, newState, oldState); }, - setTagFilter: function (tag: string) { + setTagFilter: function (filter: TagFilter) { if (currentTagFilter !== null) { this.resetTagView(); } const tasksWithTag = new Map(); for (const task of document.getElementsByClassName("task")) { - if (model.hasTag(task, tag)) { + if (filter.include(task)) { tasksWithTag.set(task.getElementsByClassName("desc")[0].textContent, [model.getPriority(task), task]); } } @@ -637,7 +642,7 @@ function BrowserUI() { } for (const task of Array.from(document.getElementsByClassName("task"))) { - if (model.hasTag(task, tag)) { + if (filter.include(task)) { task.classList.remove("hide"); } else { const superTask = highestPrioritySuperTask(task); @@ -649,7 +654,7 @@ function BrowserUI() { } } - currentTagFilter = tag; + currentTagFilter = filter; this.setTitle(); }, @@ -659,11 +664,11 @@ function BrowserUI() { if (!target) return; tag = target.textContent!; } - this.setTagFilter(tag); + this.setTagFilter({description: tag, include: task => !!model.hasTag(task, tag!)}); }, setTitle: function () { - document.title = "Vopamoi: " + currentViewState + (currentTagFilter ? ": " + currentTagFilter : ""); + document.title = "Vopamoi: " + currentViewState + (currentTagFilter ? ": " + currentTagFilter.description : ""); }, setView: function (state: string) {