Order equal-priority tasks in the switcher by least recently visited
This commit is contained in:
Vendored
+4
-3
@@ -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"));
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+12
@@ -72,7 +72,19 @@ export async function loadInbox() {
|
||||
notify("inbox");
|
||||
}
|
||||
let liveDuringLoad;
|
||||
const visitsKey = "byre.visits";
|
||||
export function lastVisits() {
|
||||
return JSON.parse(localStorage.getItem(visitsKey) ?? "{}");
|
||||
}
|
||||
function markVisited(taskId) {
|
||||
if (!taskId) {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(visitsKey, JSON.stringify({ ...lastVisits(), [taskId]: Date.now() }));
|
||||
}
|
||||
export async function selectTask(taskId) {
|
||||
markVisited(state.selectedTaskId);
|
||||
markVisited(taskId);
|
||||
state.selectedTaskId = taskId;
|
||||
state.transcript = [];
|
||||
state.lastTranscriptSeq = 0;
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+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(
|
||||
|
||||
@@ -89,7 +89,22 @@ export async function loadInbox(): Promise<void> {
|
||||
|
||||
let liveDuringLoad: ByreEvent[] | undefined;
|
||||
|
||||
const visitsKey = "byre.visits";
|
||||
|
||||
export function lastVisits(): Record<string, number> {
|
||||
return JSON.parse(localStorage.getItem(visitsKey) ?? "{}") as Record<string, number>;
|
||||
}
|
||||
|
||||
function markVisited(taskId: string | undefined): void {
|
||||
if (!taskId) {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(visitsKey, JSON.stringify({ ...lastVisits(), [taskId]: Date.now() }));
|
||||
}
|
||||
|
||||
export async function selectTask(taskId: string | undefined): Promise<void> {
|
||||
markVisited(state.selectedTaskId);
|
||||
markVisited(taskId);
|
||||
state.selectedTaskId = taskId;
|
||||
state.transcript = [];
|
||||
state.lastTranscriptSeq = 0;
|
||||
|
||||
Reference in New Issue
Block a user