| 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | |
| 3 | import { undoLatestThreadAction, useThreadUndoNotice } from "../../hooks/showThreadUndoNotice"; |
| 4 | import { shortcutLabelForCommand } from "../../keybindings"; |
| 5 | import { primaryServerKeybindingsAtom } from "../../state/server"; |
| 6 | import { Alert, AlertDescription } from "../ui/alert"; |
| 7 | import { InlineButton } from "../ui/button"; |
| 8 | |
| 9 | export 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 | } |