Add thread search, find navigation, archived and older shelves, and pin reordering
This commit is contained in:
1 parent
43347d1d58
commit
89625dddc5
17 files changed
+551
-24
No files matched your search
+44
-9
@@ -25,7 +25,7 @@ import { detailsActions, detailsCwd, RUNTIME_MODE_LABELS, threadDetails, type De
|
||||
import { paletteEntries, paletteGroups, pickerGroups, type PaletteCommand, type Picker, type PickerItem } from "../model/palette.ts";
|
||||
import { serverSettingLines, settingRows } from "../model/settings.ts";
|
||||
import { buildTimeline, type Timeline } from "../model/timeline.ts";
|
||||
import { threadRows, type Section } from "../model/threads.ts";
|
||||
import type { Section } from "../model/threads.ts";
|
||||
import { ComposerMenu } from "./ComposerMenu.tsx";
|
||||
import { ConfirmBar, type Confirmation } from "./ConfirmBar.tsx";
|
||||
import { DetailsPanel } from "./DetailsPanel.tsx";
|
||||
@@ -40,13 +40,18 @@ import { copyText, desktopNotify, ring } from "./terminalOut.ts";
|
||||
import { colors } from "./theme.ts";
|
||||
import { ThreadList } from "./ThreadList.tsx";
|
||||
import { ThreadView } from "./ThreadView.tsx";
|
||||
import { useThreadLibrary } from "./useThreadLibrary.ts";
|
||||
import { usePaletteSearch } from "./usePaletteSearch.ts";
|
||||
import { useThreadFind } from "./useThreadFind.ts";
|
||||
import { ThreadFindBar } from "./ThreadFindBar.tsx";
|
||||
import { mergeThreadShells, messageMatchGroups } from "../model/search.ts";
|
||||
|
||||
/**
|
||||
* "input": typing goes to the composer. "nav": single keys move, scroll, approve.
|
||||
* "details": j/k move through the details panel. "settings": j/k move through settings.
|
||||
* The rest are overlays with their own input.
|
||||
*/
|
||||
type Mode = "input" | "nav" | "filter" | "details" | "palette" | "picker" | "confirm" | "settings";
|
||||
type Mode = "input" | "nav" | "filter" | "details" | "palette" | "picker" | "confirm" | "settings" | "find";
|
||||
|
||||
/** Holding j/k skims past threads; only subscribe to one you stop on. */
|
||||
const SUBSCRIBE_DELAY_MS = 120;
|
||||
@@ -158,8 +163,10 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
const allRows = useMemo(() => threadRows(shell.snapshot, { query: filter }), [shell.snapshot, filter]);
|
||||
const unfold = showFolded || filter.trim() !== "";
|
||||
const library = useThreadLibrary(session, shell.snapshot, filter);
|
||||
const allRows = library.allRows;
|
||||
useEffect(() => { if (!attached) setSelectedId(undefined); }, [library.archived]);
|
||||
const unfold = library.archived || showFolded || filter.trim() !== "";
|
||||
const rows = useMemo(() => (unfold ? allRows : allRows.filter((row) => !FOLDED_SECTIONS.includes(row.section))), [allRows, unfold]);
|
||||
const collapsed = useMemo(
|
||||
() => new Map(unfold ? [] : FOLDED_SECTIONS.map((section) => [section, allRows.filter((row) => row.section === section).length] as const)),
|
||||
@@ -169,7 +176,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
const threadId = selectedId ?? rows[0]?.thread.id;
|
||||
const selectedIndex = rows.findIndex((row) => row.thread.id === threadId);
|
||||
const threadRow = allRows.find((row) => row.thread.id === threadId);
|
||||
const threadShell = threadRow?.thread ?? shell.snapshot?.threads.find((thread) => thread.id === threadId) ?? (threadId ? familyShells.get(threadId) : undefined);
|
||||
const threadShell = threadRow?.thread ?? shell.snapshot?.threads.find((thread) => thread.id === threadId) ?? library.archive?.threads.find((thread) => thread.id === threadId) ?? library.merged?.threads.find((thread) => thread.id === threadId) ?? (threadId ? familyShells.get(threadId) : undefined);
|
||||
const composerKey: string = draft ? DRAFT_KEY : (threadId ?? "");
|
||||
// Pin the initial selection to a thread, or it would follow whatever sorts first.
|
||||
useEffect(() => {
|
||||
@@ -213,11 +220,13 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
const timeline = useMemo(() => {
|
||||
if (!thread?.projection || !watchedId) return null;
|
||||
const previous = previousTimeline.current?.id === watchedId ? previousTimeline.current.timeline : null;
|
||||
const next = buildTimeline(thread.projection, { expandAll }, previous);
|
||||
const next = buildTimeline(thread.projection, { expandAll: expandAll || mode === "find" }, previous);
|
||||
previousTimeline.current = { id: watchedId, timeline: next };
|
||||
return next;
|
||||
}, [thread?.projection, watchedId, expandAll]);
|
||||
}, [thread?.projection, watchedId, expandAll, mode === "find"]);
|
||||
const current = watchedId === threadId ? timeline : null;
|
||||
const find = useThreadFind(session, watchedId, thread, current, mode === "find");
|
||||
const openFind = () => { setDiff(null); setSettingsIndex(null); setMode("find"); };
|
||||
const pendingApproval = current?.pending.approvals[0];
|
||||
const pendingInput = current?.pending.userInputs[0];
|
||||
const questionDraft = pendingInput ? (questionDrafts.get(pendingInput.requestId) ?? { index: 0, answers: {} }) : undefined;
|
||||
@@ -592,6 +601,9 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
return run(`Snoozed until ${preset.whenLabel}`, () => session.snoozeThread(id, preset.snoozedUntil));
|
||||
}
|
||||
switch (action) {
|
||||
case "find":
|
||||
openThread(id);
|
||||
return openFind();
|
||||
case "settle":
|
||||
return run("Settled", () => session.settleThread(id));
|
||||
case "unsettle":
|
||||
@@ -962,9 +974,13 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
command("settings", "Settings", openSettings, { keywords: ["preferences", "config", "options", "notifications", "alerts"] });
|
||||
command("quit", "Quit tui3", quit, { shortcut: "q", keywords: ["exit"] });
|
||||
|
||||
commands.push(...library.commands(threadId));
|
||||
if (threadId && !draft) command("find", "Find in thread", openFind, { shortcut: "f", keywords: ["search", "messages", "plans"] });
|
||||
const paletteSearch = usePaletteSearch(session, library.merged, paletteQuery, mode === "palette");
|
||||
const paletteSnapshot = useMemo(() => mergeThreadShells(library.merged, paletteSearch.result?.threads ?? []), [library.merged, paletteSearch.result]);
|
||||
const commandKey = commands.map((candidate) => `${candidate.id}:${candidate.title}`).join("|");
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- commands are rebuilt each render; commandKey tracks what changed.
|
||||
const groups = useMemo(() => (mode === "palette" ? paletteGroups({ query: paletteQuery, commands, snapshot: shell.snapshot, now }) : []), [mode, paletteQuery, commandKey, shell.snapshot]);
|
||||
const groups = useMemo(() => (mode === "palette" ? messageMatchGroups(paletteGroups({ query: paletteQuery, commands, snapshot: paletteSnapshot, now }), paletteSearch.result, paletteSnapshot, paletteQuery, now) : []), [mode, paletteQuery, commandKey, paletteSnapshot, paletteSearch.result]);
|
||||
const entries = paletteEntries(groups);
|
||||
const openPalette = () => {
|
||||
if (mode !== "palette" && mode !== "confirm") returnMode.current = mode === "filter" ? "nav" : mode;
|
||||
@@ -1078,6 +1094,15 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
};
|
||||
|
||||
useKeyboard((key) => {
|
||||
if (mode === "find") {
|
||||
if (key.ctrl && key.name === "c") return quit();
|
||||
if (key.ctrl && key.name === "k") return openPalette(), key.preventDefault();
|
||||
if (find.handleKey(key)) {
|
||||
if (key.name === "escape") setMode("nav");
|
||||
return key.preventDefault();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mode === "input" && menuKey(key)) return key.preventDefault();
|
||||
if (mode === "picker") {
|
||||
if (key.ctrl && key.name === "c") return quit();
|
||||
@@ -1176,6 +1201,8 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
return setMode("nav");
|
||||
}
|
||||
}
|
||||
if (mode === "nav" && library.key(key, threadId)) return key.preventDefault();
|
||||
if (mode === "nav" && key.name === "f" && threadId && !draft) return openFind(), key.preventDefault();
|
||||
switch (key.name) {
|
||||
case "q":
|
||||
if (diff) return setDiff(null);
|
||||
@@ -1335,6 +1362,9 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
if (target) openThreadMenu(target);
|
||||
}}
|
||||
onUnfold={() => setShowFolded(true)}
|
||||
showMore={unfold && library.hasOlder}
|
||||
onShowMore={() => void library.loadOlder()}
|
||||
shelfStatus={library.error ?? (library.loading ? "Loading…" : library.archived ? "Archived threads · A to go back" : null)}
|
||||
/>
|
||||
)}
|
||||
<box flexDirection="column" flexGrow={1} minHeight={0}>
|
||||
@@ -1354,7 +1384,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
<DiffView diff={diff} scrollRef={scrollRef} />
|
||||
) : draft ? (
|
||||
<DraftView lines={draftLines} />
|
||||
) : threadId && detailsInPlace ? (
|
||||
) : threadId && detailsInPlace && mode !== "find" ? (
|
||||
<box flexGrow={1} minHeight={0} flexDirection="column">
|
||||
{detailsPanel(true)}
|
||||
</box>
|
||||
@@ -1365,6 +1395,8 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
title={title}
|
||||
detail={threadShell?.branch ?? ""}
|
||||
timeline={current}
|
||||
findQuery={find.open ? find.query.trim() : ""}
|
||||
findMatch={find.match}
|
||||
history={watchedId === threadId ? (thread?.history ?? null) : null}
|
||||
loading={watchedId !== threadId || thread?.status === "loading"}
|
||||
error={thread?.error}
|
||||
@@ -1379,6 +1411,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
<text fg={colors.muted}>{shell.snapshot ? "No thread selected." : "Waiting for threads…"}</text>
|
||||
</box>
|
||||
)}
|
||||
{find.open ? <ThreadFindBar query={find.query} focused={mode === "find"} data={find.data} pending={find.pending} error={find.error} onQuery={find.onQuery} onStep={find.step} onClose={() => setMode("nav")} /> : null}
|
||||
{mode !== "confirm" && pendingInput && questionDraft ? <QuestionPanel request={pendingInput} index={questionDraft.index} draft={questionDraft.answers[pendingInput.questions[questionDraft.index]?.id ?? ""]} /> : null}
|
||||
{mode === "confirm" && confirmation ? (
|
||||
<ConfirmBar
|
||||
@@ -1451,6 +1484,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
{mode === "palette" ? (
|
||||
<Palette
|
||||
query={paletteQuery}
|
||||
status={paletteSearch.error ?? (paletteSearch.pending ? "Searching messages…" : null)}
|
||||
groups={groups}
|
||||
selected={Math.min(paletteIndex, Math.max(0, entries.length - 1))}
|
||||
width={width}
|
||||
@@ -1487,6 +1521,7 @@ function hints(
|
||||
mode: Mode,
|
||||
state: { readonly draft: boolean; readonly config: Tui3Config; readonly approval: boolean; readonly question: boolean; readonly working: boolean; readonly attached: boolean; readonly diff: boolean; readonly parent: boolean },
|
||||
): string {
|
||||
if (mode === "find") return "enter next match · shift+enter previous · ctrl+n/p match · esc close find";
|
||||
if (mode === "filter") return "enter done · esc close";
|
||||
if (mode === "palette") return "↑/↓ move · enter run · esc close";
|
||||
if (mode === "picker") return "↑/↓ move · enter choose · esc close";
|
||||
|
||||
Reference in new issue
Block a user