1import { useAtomValue } from "@effect/atom-react";
2
3import { undoLatestThreadAction, useThreadUndoNotice } from "../../hooks/showThreadUndoNotice";
4import { shortcutLabelForCommand } from "../../keybindings";
5import { primaryServerKeybindingsAtom } from "../../state/server";
6import { Alert, AlertDescription } from "../ui/alert";
7import { InlineButton } from "../ui/button";
8
9export function SidebarThreadUndoNotice() {
10 const notice = useThreadUndoNotice((state) => state.notice);
11 const keybindings = useAtomValue(primaryServerKeybindingsAtom);
12
13 if (!notice) return null;
14 const shortcut = shortcutLabelForCommand(keybindings, "thread.undo");
15 const noun = `${notice.action === "Discarded" ? "draft" : "thread"}${notice.count === 1 ? "" : "s"}`;
16
17 return (
18 <Alert role="status" variant="sidebar">
19 <AlertDescription>
20 {notice.action} {notice.count} {noun},{" "}
21 <InlineButton onClick={undoLatestThreadAction}>
22 {shortcut ? `${shortcut} to undo` : "Undo"}
23 </InlineButton>
24 </AlertDescription>
25 </Alert>
26 );
27}