Abort,
}
+interface TagFilter {
+ description: string;
+ include: (task: Element) => boolean;
+}
+
function BrowserUI() {
const viewColors: { [key: string]: string } = {
all: "Gold",
todo: "White",
waiting: "MediumOrchid",
};
- var currentTagFilter: string | null = null;
+ var currentTagFilter: TagFilter | null = null;
var currentViewState = "todo";
var taskFocusedBeforeJumpingToInput: HTMLElement | null = null;
var lastTagNameEntered = "";
return ui.setState(createTimestamp, newState, oldState);
},
- setTagView: function (tag: string | null = null) {
- if (tag === null) {
- const target = this.currentTag();
- if (!target) return;
- tag = target.textContent!;
- }
-
+ 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]);
}
}
}
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);
}
}
- currentTagFilter = tag;
+ currentTagFilter = filter;
this.setTitle();
},
+ setTagView: function (tag: string | null = null) {
+ if (tag === null) {
+ const target = this.currentTag();
+ if (!target) return;
+ tag = target.textContent!;
+ }
+ 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) {
},
setUntaggedView: function () {
- if (currentTagFilter !== null) {
- this.resetTagView();
- }
- for (const task of document.getElementsByClassName("task")) {
- if (task.getElementsByClassName("tag").length === 0) {
- task.classList.remove("hide");
- } else {
- task.classList.add("hide");
- }
- }
+ this.setTagFilter({description: "(untagged)", include: task => task.getElementsByClassName("tag").length === 0});
},
undo: function () {