feat(ui,api): strip board redesign - island, rail by day, context view, server search, vault graph
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import type { ConversationSummary } from "$lib/api/types";
|
||||
import { parseDate } from "$lib/format";
|
||||
import { byActivity } from "$lib/shell/state";
|
||||
|
||||
export interface DayGroup {
|
||||
branches: ConversationSummary[];
|
||||
day: string;
|
||||
deep: ConversationSummary[];
|
||||
label: string;
|
||||
live: boolean;
|
||||
master: ConversationSummary | null;
|
||||
others: ConversationSummary[];
|
||||
}
|
||||
|
||||
const DAY_MS = 86_400_000;
|
||||
|
||||
function localDay(iso: string | null | undefined): string {
|
||||
const date = parseDate(iso) ?? new Date();
|
||||
const y = date.getFullYear();
|
||||
const m = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const d = String(date.getDate()).padStart(2, "0");
|
||||
return `${y}-${m}-${d}`;
|
||||
}
|
||||
|
||||
export function dayLabel(day: string, now = new Date()): string {
|
||||
const today = localDay(now.toISOString());
|
||||
const yesterday = localDay(new Date(now.getTime() - DAY_MS).toISOString());
|
||||
if (day === today) {
|
||||
return "Today";
|
||||
}
|
||||
if (day === yesterday) {
|
||||
return "Yesterday";
|
||||
}
|
||||
const date = new Date(`${day}T12:00:00`);
|
||||
return date.toLocaleDateString(undefined, {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
weekday: "short",
|
||||
});
|
||||
}
|
||||
|
||||
function activityOf(row: ConversationSummary): string {
|
||||
return row.last_activity_at ?? row.created_at ?? "";
|
||||
}
|
||||
|
||||
// Days as the operator remembers them: a master per day, its branches
|
||||
// under it, deep chats by the day they last moved, forks with their
|
||||
// parent's day. Jobs never enter the rail.
|
||||
export function groupByDay(
|
||||
rows: ConversationSummary[],
|
||||
now = new Date()
|
||||
): DayGroup[] {
|
||||
const groups = new Map<string, DayGroup>();
|
||||
const dayOfMaster = new Map<string, string>();
|
||||
const group = (day: string): DayGroup => {
|
||||
let found = groups.get(day);
|
||||
if (!found) {
|
||||
found = {
|
||||
branches: [],
|
||||
day,
|
||||
deep: [],
|
||||
label: dayLabel(day, now),
|
||||
live: false,
|
||||
master: null,
|
||||
others: [],
|
||||
};
|
||||
groups.set(day, found);
|
||||
}
|
||||
return found;
|
||||
};
|
||||
const masters = rows
|
||||
.filter((row) => row.kind === "master")
|
||||
.sort((a, b) => (b.created_at ?? "").localeCompare(a.created_at ?? ""));
|
||||
for (const master of masters) {
|
||||
const day = localDay(master.created_at);
|
||||
dayOfMaster.set(master.id, day);
|
||||
const g = group(day);
|
||||
if (!g.master || master.status === "open") {
|
||||
g.master = master;
|
||||
} else {
|
||||
g.others.push(master);
|
||||
}
|
||||
}
|
||||
for (const row of rows) {
|
||||
if (row.kind === "master" || row.kind === "job") {
|
||||
continue;
|
||||
}
|
||||
const parentDay = row.parent ? dayOfMaster.get(row.parent) : undefined;
|
||||
const day = parentDay ?? localDay(activityOf(row));
|
||||
const g = group(day);
|
||||
if (row.kind === "branch") {
|
||||
g.branches.push(row);
|
||||
} else if (row.kind === "deep") {
|
||||
g.deep.push(row);
|
||||
} else {
|
||||
g.others.push(row);
|
||||
}
|
||||
}
|
||||
const out = [...groups.values()];
|
||||
for (const g of out) {
|
||||
g.branches.sort(byActivity);
|
||||
g.deep.sort(byActivity);
|
||||
g.others.sort(byActivity);
|
||||
g.live = [g.master, ...g.branches, ...g.deep, ...g.others].some(
|
||||
(row) => row && (row.running_turn || row.pending_question)
|
||||
);
|
||||
}
|
||||
return out.sort((a, b) => b.day.localeCompare(a.day));
|
||||
}
|
||||
Reference in New Issue
Block a user