Open History to see the last commit
1import { useAtomValue } from "@effect/atom-react";
2import { useState } from "react";
3
4import {
5 threadUndoLabel,
6 threadUndoNoticeSummary,
7 undoLatestThreadAction,
8 useThreadUndoNotice,
9} from "../../hooks/showThreadUndoNotice";
10import { cn } from "../../lib/utils";
11import { primaryServerKeybindingsAtom } from "../../state/server";
12import { InlineButton } from "../ui/button";
13
14export function SidebarThreadUndoNotice({ className }: { className?: string }) {
15 const notice = useThreadUndoNotice((state) => state.notice);
16 const keybindings = useAtomValue(primaryServerKeybindingsAtom);
17 const summary = notice ? threadUndoNoticeSummary(notice) : null;
18
19 // Keeps the last text on screen while it fades out, then unmounts on transitionend.
20 const [shownSummary, setShownSummary] = useState(summary);
21 if (summary && summary !== shownSummary) setShownSummary(summary);
22 const text = summary ?? shownSummary;
23 if (!text) return null;
24
25 return (
26 <div
27 role="group"
28 aria-hidden={!summary}
29 inert={!summary}
30 onTransitionEnd={(event) => {
31 if (!summary && event.target === event.currentTarget) setShownSummary(null);
32 }}
33 className={cn(
34 "flex gap-1 px-2 text-2xs leading-6 text-sidebar-muted-foreground transition-opacity duration-200 ease-out starting:opacity-0",
35 !summary && "opacity-0",
36 className,
37 )}
38 >
39 <span className="min-w-0 truncate">{text},</span>
40 <InlineButton onClick={undoLatestThreadAction}>{threadUndoLabel(keybindings)}</InlineButton>
41 </div>
42 );
43}