Order equal-priority tasks in the switcher by least recently visited
This commit is contained in:
+4
-3
@@ -1,7 +1,7 @@
|
||||
import { post } from "./api.js";
|
||||
import { errorText, h, replace, showAlert } from "./dom.js";
|
||||
import { openTranscript, type View } from "./panes.js";
|
||||
import { activeTasks, currentSession, findTask, onEach, state } from "./state.js";
|
||||
import { activeTasks, currentSession, findTask, lastVisits, onEach, state } from "./state.js";
|
||||
|
||||
export function mountNavbar(root: HTMLElement, show: (view: View) => void): void {
|
||||
const crumb = h("button", { class: "crumb", title: "Switch task (⌘K)" });
|
||||
@@ -93,10 +93,11 @@ function openSwitcher(): void {
|
||||
const title = input.value.trim();
|
||||
const q = title.toLowerCase();
|
||||
const inbox = (taskId: string) => state.inbox.filter((item) => item.task_id === taskId).length;
|
||||
const visits = lastVisits();
|
||||
const matches = activeTasks()
|
||||
.filter(({ project, task }) => `${project.name} ${task.title}`.toLowerCase().includes(q))
|
||||
.map((m) => ({ ...m, count: inbox(m.task.id) }))
|
||||
.sort((a, b) => Number(b.count > 0) - Number(a.count > 0));
|
||||
.map((m) => ({ ...m, count: inbox(m.task.id), visited: visits[m.task.id] ?? 0 }))
|
||||
.sort((a, b) => Number(b.count > 0) - Number(a.count > 0) || a.visited - b.visited);
|
||||
rows = matches.map(({ project, task, count }) => {
|
||||
const sess = currentSession(task.id);
|
||||
const el = h(
|
||||
|
||||
Reference in New Issue
Block a user