Skip to content
Source
Sign inSign up

KeybindingsUpdateToast.tsx

40 lines1.6 KB

1import { appAtomRegistry, subscribeAtomChanges } from "../rpc/atomRegistry";
2import { primaryEnvironmentIdAtom } from "../state/primaryEnvironment";
3import { primaryServerConfigAtom, primaryServerConfigEventAtom } from "../state/server";
4import { KeybindingsConfigWarning } from "./KeybindingsConfigWarning";
5import { createKeybindingsUpdateToastController } from "./KeybindingsUpdateToast.logic";
6import { stackedThreadToast, toastManager } from "./ui/toast";
7​
8/** Toasts each keybindings reload the primary server reports. */
9export function startKeybindingsUpdateToasts(): () => void {
10 const controller = createKeybindingsUpdateToastController({});
11 return subscribeAtomChanges(primaryServerConfigEventAtom, (event) => {
12 const decision = controller.handle(event);
13 if (!decision) return;
14​
15 if (decision._tag === "Success") {
16 toastManager.add({
17 type: "success",
18 title: "Keybindings updated",
19 description: "Keybindings configuration reloaded successfully.",
20 });
21 return;
22 }
23​
24 const serverConfig = appAtomRegistry.get(primaryServerConfigAtom);
25 toastManager.add(
26 stackedThreadToast({
27 type: "warning",
28 title: "Invalid keybindings configuration",
29 description: (
30 <KeybindingsConfigWarning
31 message={decision.message}
32 environmentId={appAtomRegistry.get(primaryEnvironmentIdAtom)}
33 configPath={serverConfig?.keybindingsConfigPath ?? null}
34 availableEditors={serverConfig?.availableEditors ?? []}
35 />
36 ),
37 }),
38 );
39 });