The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | import { msg, useMessages } from "gt-react"; |
| 3 | import { Undo2Icon } from "lucide-react"; |
| 4 | import { useState } from "react"; |
| 5 | |
| 6 | import { |
| 7 | threadUndoLabel, |
| 8 | undoLatestThreadAction, |
| 9 | useThreadUndoNotice, |
| 10 | } from "../../hooks/showThreadUndoNotice"; |
| 11 | import { cn } from "../../lib/utils"; |
| 12 | import { primaryServerKeybindingsAtom } from "../../state/server"; |
| 13 | import { InlineButton } from "../ui/button"; |
| 14 | import { SidebarMenuItem } from "../ui/sidebar"; |
| 15 | |
| 16 | const SHORT_SUMMARY = { |
| 17 | Settled: msg("{count, plural, =1 {Settled,} other {Settled {count},}}"), |
| 18 | Snoozed: msg("{count, plural, =1 {Snoozed,} other {Snoozed {count},}}"), |
| 19 | Unpinned: msg("{count, plural, =1 {Unpinned,} other {Unpinned {count},}}"), |
| 20 | Archived: msg("{count, plural, =1 {Archived,} other {Archived {count},}}"), |
| 21 | Discarded: msg("{count, plural, =1 {Discarded,} other {Discarded {count},}}"), |
| 22 | }; |
| 23 | |
| 24 | /** Fills the free space in the sidebar footer's utility row, so it never moves or covers the list. */ |
| 25 | export function SidebarThreadUndoNotice() { |
| 26 | const notice = useThreadUndoNotice((state) => state.notice); |
| 27 | const keybindings = useAtomValue(primaryServerKeybindingsAtom); |
| 28 | const m = useMessages(); |
| 29 | // Short enough to fit beside the utility icons; screen readers hear the full summary. |
| 30 | const summary = notice ? m(SHORT_SUMMARY[notice.action], { count: notice.count }) : null; |
| 31 | |
| 32 | // Keeps the last text on screen while it fades out, then unmounts on transitionend. |
| 33 | const [shownSummary, setShownSummary] = useState(summary); |
| 34 | if (summary && summary !== shownSummary) setShownSummary(summary); |
| 35 | const text = summary ?? shownSummary; |
| 36 | if (!text) return null; |
| 37 | |
| 38 | return ( |
| 39 | <SidebarMenuItem |
| 40 | className="@container flex min-w-0 flex-1" |
| 41 | aria-hidden={!summary} |
| 42 | inert={!summary} |
| 43 | > |
| 44 | <div |
| 45 | onTransitionEnd={(event) => { |
| 46 | if (!summary && event.target === event.currentTarget) setShownSummary(null); |
| 47 | }} |
| 48 | // Reversed wrap: a summary that does not fit beside the undo button drops to a |
| 49 | // second line that overflow hides, instead of truncating mid-word. Browse mode |
| 50 | // reads the button first; the live announcement carries the full sentence. |
| 51 | className={cn( |
| 52 | "flex h-6 min-w-0 flex-1 flex-row-reverse flex-wrap gap-x-1 overflow-hidden text-2xs leading-6 whitespace-nowrap text-sidebar-muted-foreground transition-opacity duration-200 ease-out starting:opacity-0", |
| 53 | !summary && "opacity-0", |
| 54 | )} |
| 55 | > |
| 56 | <InlineButton className="min-w-0 shrink" onClick={undoLatestThreadAction}> |
| 57 | {/* The icon's negative margin cancels its width, so beside the label it sits in |
| 58 | clipped space; once the label is too wide it wraps away and the icon shows. */} |
| 59 | <span className="flex h-6 min-w-0 flex-wrap justify-end overflow-hidden"> |
| 60 | <Undo2Icon className="-ml-4 h-6 w-4 @max-[1rem]:invisible" /> |
| 61 | <span>{threadUndoLabel(keybindings, m)}</span> |
| 62 | </span> |
| 63 | </InlineButton> |
| 64 | <span>{text}</span> |
| 65 | </div> |
| 66 | </SidebarMenuItem> |
| 67 | ); |
| 68 | } |