2023-01-23 16:54:35 +01:00
|
|
|
import { atom, useAtom } from "jotai";
|
|
|
|
import { actionClearCanvas } from "../actions";
|
|
|
|
import { t } from "../i18n";
|
2023-03-03 12:58:36 +01:00
|
|
|
import { jotaiScope } from "../jotai";
|
2023-01-23 16:54:35 +01:00
|
|
|
import { useExcalidrawActionManager } from "./App";
|
|
|
|
import ConfirmDialog from "./ConfirmDialog";
|
|
|
|
|
|
|
|
export const activeConfirmDialogAtom = atom<"clearCanvas" | null>(null);
|
|
|
|
|
|
|
|
export const ActiveConfirmDialog = () => {
|
|
|
|
const [activeConfirmDialog, setActiveConfirmDialog] = useAtom(
|
|
|
|
activeConfirmDialogAtom,
|
2023-03-03 12:58:36 +01:00
|
|
|
jotaiScope,
|
2023-01-23 16:54:35 +01:00
|
|
|
);
|
|
|
|
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;
|
|
|
|
};
|