snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
This commit is contained in:
22
apps/yaak-client/lib/dialog.ts
Normal file
22
apps/yaak-client/lib/dialog.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { atom } from "jotai";
|
||||
import type { DialogInstance } from "../components/Dialogs";
|
||||
import { jotaiStore } from "./jotai";
|
||||
|
||||
export const dialogsAtom = atom<DialogInstance[]>([]);
|
||||
|
||||
export function toggleDialog({ id, ...props }: DialogInstance) {
|
||||
const dialogs = jotaiStore.get(dialogsAtom);
|
||||
if (dialogs.some((d) => d.id === id)) {
|
||||
hideDialog(id);
|
||||
} else {
|
||||
showDialog({ id, ...props });
|
||||
}
|
||||
}
|
||||
|
||||
export function showDialog({ id, ...props }: DialogInstance) {
|
||||
jotaiStore.set(dialogsAtom, (a) => [...a.filter((d) => d.id !== id), { id, ...props }]);
|
||||
}
|
||||
|
||||
export function hideDialog(id: string) {
|
||||
jotaiStore.set(dialogsAtom, (a) => a.filter((d) => d.id !== id));
|
||||
}
|
||||
Reference in New Issue
Block a user