| 1 | import { useCallback } from "react"; |
| 2 | |
| 3 | import { useSessionStore } from "@/lib/store/sessions"; |
| 4 | import type { SessionDetail } from "@/lib/ipc/types"; |
| 5 | |
| 6 | interface ArchiveChatBannerProps { |
| 7 | detail: SessionDetail; |
| 8 | } |
| 9 | |
| 10 | /** Footer for an archive session that can't be resumed (transcripts |
| 11 | * gone from disk) but whose cwd is still known. One button: start |
| 12 | * a brand-new session in that cwd. */ |
| 13 | export function ArchiveChatBanner({ detail }: ArchiveChatBannerProps) { |
| 14 | const beginNewSession = useSessionStore((s) => s.beginNewSession); |
| 15 | const cwd = detail.summary.cwd; |
| 16 | const basename = cwd ? cwdBasename(cwd) : "project"; |
| 17 | |
| 18 | const onStart = useCallback(() => { |
| 19 | if (!cwd) return; |
| 20 | beginNewSession(cwd, basename); |
| 21 | }, [cwd, basename, beginNewSession]); |
| 22 | |
| 23 | if (!cwd) return null; |
| 24 | return ( |
| 25 | <div className="shrink-0 border-t border-border bg-bg-1"> |
| 26 | <div className="mx-auto flex max-w-4xl items-center justify-between gap-4 px-4 py-3"> |
| 27 | <div className="min-w-0 text-[11px] text-fg-3"> |
| 28 | <div>this archive has prompt history but no transcripts on disk.</div> |
| 29 | <div className="truncate"> |
| 30 | original cwd: <span className="font-mono text-fg-2">{cwd}</span> |
| 31 | </div> |
| 32 | </div> |
| 33 | <button |
| 34 | type="button" |
| 35 | onClick={onStart} |
| 36 | className="shrink-0 rounded border border-accent/60 bg-accent/20 px-3 py-2 text-[12px] font-medium text-accent transition hover:bg-accent/30" |
| 37 | > |
| 38 | start new session here |
| 39 | </button> |
| 40 | </div> |
| 41 | </div> |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | function cwdBasename(cwd: string): string { |
| 46 | const trimmed = cwd.replace(/\/$/, ""); |
| 47 | const idx = trimmed.lastIndexOf("/"); |
| 48 | return idx >= 0 ? trimmed.slice(idx + 1) : trimmed; |
| 49 | } |