Order equal-priority tasks in the switcher by least recently visited

This commit is contained in:
Ian Gulliver
2026-10-14 23:23:25 -07:00
parent c6e57a4740
commit 4dc86e5479
7 changed files with 38 additions and 9 deletions
+4 -3
View File
@@ -1,7 +1,7 @@
import { post } from "./api.js";
import { errorText, h, replace, showAlert } from "./dom.js";
import { openTranscript } 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, show) {
const crumb = h("button", { class: "crumb", title: "Switch task (⌘K)" });
crumb.onclick = openSwitcher;
@@ -79,10 +79,11 @@ function openSwitcher() {
const title = input.value.trim();
const q = title.toLowerCase();
const inbox = (taskId) => 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("li", {}, h("span", { class: `dot ${sess?.state ?? "none"}`, title: sess?.state ?? "no session" }), h("span", { class: "task-title" }, h("span", { class: "project-name" }, project.name), " ", task.title), count > 0 && h("span", { class: "badge", title: "inbox items" }, count), h("span", { class: "task-state" }, sess?.state ?? "no agent"));