36 lines
989 B
TypeScript
36 lines
989 B
TypeScript
|
import { atom, useAtom } from "jotai";
|
||
|
import { actionClearCanvas } from "../actions";
|
||
|
import { t } from "../i18n";
|
||
|
import { useExcalidrawActionManager } from "./App";
|
||
|
import ConfirmDialog from "./ConfirmDialog";
|
||
|
|
||
|
export const activeConfirmDialogAtom = atom<"clearCanvas" | null>(null);
|
||
|
|
||
|
export const ActiveConfirmDialog = () => {
|
||
|
const [activeConfirmDialog, setActiveConfirmDialog] = useAtom(
|
||
|
activeConfirmDialogAtom,
|
||
|
);
|
||
|
const actionManager = useExcalidrawActionManager();
|
||
|
|
||
|
if (!activeConfirmDialog) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
if (activeConfirmDialog === "clearCanvas") {
|
||
|
return (
|
||
|
<ConfirmDialog
|
||
|
onConfirm={() => {
|
||
|
actionManager.executeAction(actionClearCanvas);
|
||
|
setActiveConfirmDialog(null);
|
||
|
}}
|
||
|
onCancel={() => setActiveConfirmDialog(null)}
|
||
|
title={t("clearCanvasDialog.title")}
|
||
|
>
|
||
|
<p className="clear-canvas__content"> {t("alerts.clearReset")}</p>
|
||
|
</ConfirmDialog>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
};
|