This commit is contained in:
Philipinho
2026-03-24 21:46:34 +00:00
parent 4730dc2fb9
commit 6bdb0516b2
4 changed files with 28 additions and 4 deletions
@@ -8,6 +8,7 @@ import {
} from "@/features/editor/components/table/types/types.ts"; } from "@/features/editor/components/table/types/types.ts";
import { import {
ActionIcon, ActionIcon,
LoadingOverlay,
Modal, Modal,
Text, Text,
Tooltip, Tooltip,
@@ -46,6 +47,8 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
const computedColorScheme = useComputedColorScheme(); const computedColorScheme = useComputedColorScheme();
const isDirtyRef = useRef(false); const isDirtyRef = useRef(false);
const isSavingRef = useRef(false); const isSavingRef = useRef(false);
const [isSaving, setIsSaving] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const editorState = useEditorState({ const editorState = useEditorState({
editor, editor,
@@ -140,6 +143,7 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
if (isSavingRef.current) return; if (isSavingRef.current) return;
isSavingRef.current = true; isSavingRef.current = true;
setIsSaving(true);
try { try {
const svgString = decodeBase64ToSvgString(svgXml); const svgString = decodeBase64ToSvgString(svgXml);
@@ -167,6 +171,7 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
isDirtyRef.current = false; isDirtyRef.current = false;
} finally { } finally {
isSavingRef.current = false; isSavingRef.current = false;
setIsSaving(false);
} }
}, [editor, editorState?.attachmentId]); }, [editor, editorState?.attachmentId]);
@@ -196,6 +201,7 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
const handleOpen = useCallback(async () => { const handleOpen = useCallback(async () => {
if (!editorState?.src) return; if (!editorState?.src) return;
setIsLoading(true);
try { try {
const url = getFileUrl(editorState.src); const url = getFileUrl(editorState.src);
const request = await fetch(url, { const request = await fetch(url, {
@@ -213,6 +219,7 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} finally { } finally {
setIsLoading(false);
isDirtyRef.current = false; isDirtyRef.current = false;
open(); open();
} }
@@ -307,6 +314,7 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
size="lg" size="lg"
aria-label={t("Edit")} aria-label={t("Edit")}
variant="subtle" variant="subtle"
loading={isLoading}
> >
<IconEdit size={18} /> <IconEdit size={18} />
</ActionIcon> </ActionIcon>
@@ -339,7 +347,8 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
<Modal.Root opened={opened} onClose={handleClose} fullScreen closeOnEscape={false}> <Modal.Root opened={opened} onClose={handleClose} fullScreen closeOnEscape={false}>
<Modal.Overlay /> <Modal.Overlay />
<Modal.Content style={{ overflow: "hidden" }}> <Modal.Content style={{ overflow: "hidden" }}>
<Modal.Body> <Modal.Body pos="relative">
<LoadingOverlay visible={isSaving} />
<div style={{ height: "100vh" }}> <div style={{ height: "100vh" }}>
<DrawIoEmbed <DrawIoEmbed
ref={drawioRef} ref={drawioRef}
@@ -2,6 +2,7 @@ import { NodeViewProps, NodeViewWrapper } from "@tiptap/react";
import { import {
ActionIcon, ActionIcon,
Card, Card,
LoadingOverlay,
Modal, Modal,
Text, Text,
useComputedColorScheme, useComputedColorScheme,
@@ -34,6 +35,7 @@ export default function DrawioView(props: NodeViewProps) {
const computedColorScheme = useComputedColorScheme(); const computedColorScheme = useComputedColorScheme();
const isDirtyRef = useRef(false); const isDirtyRef = useRef(false);
const isSavingRef = useRef(false); const isSavingRef = useRef(false);
const [isSaving, setIsSaving] = useState(false);
const handleOpen = async () => { const handleOpen = async () => {
if (!editor.isEditable) { if (!editor.isEditable) {
@@ -47,6 +49,7 @@ export default function DrawioView(props: NodeViewProps) {
if (isSavingRef.current) return; if (isSavingRef.current) return;
isSavingRef.current = true; isSavingRef.current = true;
setIsSaving(true);
try { try {
const svgString = decodeBase64ToSvgString(svgXml); const svgString = decodeBase64ToSvgString(svgXml);
@@ -79,6 +82,7 @@ export default function DrawioView(props: NodeViewProps) {
isDirtyRef.current = false; isDirtyRef.current = false;
} finally { } finally {
isSavingRef.current = false; isSavingRef.current = false;
setIsSaving(false);
} }
}; };
@@ -136,7 +140,8 @@ export default function DrawioView(props: NodeViewProps) {
<Modal.Root opened={opened} onClose={handleClose} fullScreen closeOnEscape={false}> <Modal.Root opened={opened} onClose={handleClose} fullScreen closeOnEscape={false}>
<Modal.Overlay /> <Modal.Overlay />
<Modal.Content style={{ overflow: "hidden" }}> <Modal.Content style={{ overflow: "hidden" }}>
<Modal.Body> <Modal.Body pos="relative">
<LoadingOverlay visible={isSaving} />
<div style={{ height: "100vh" }}> <div style={{ height: "100vh" }}>
<DrawIoEmbed <DrawIoEmbed
ref={drawioRef} ref={drawioRef}
@@ -56,6 +56,8 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
const computedColorScheme = useComputedColorScheme(); const computedColorScheme = useComputedColorScheme();
const isDirtyRef = useRef(false); const isDirtyRef = useRef(false);
const isSavingRef = useRef(false); const isSavingRef = useRef(false);
const [isSaving, setIsSaving] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const isInitialLoadRef = useRef(true); const isInitialLoadRef = useRef(true);
const lastFingerprintRef = useRef(""); const lastFingerprintRef = useRef("");
@@ -153,6 +155,7 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
const handleOpen = useCallback(async () => { const handleOpen = useCallback(async () => {
if (!editorState?.src) return; if (!editorState?.src) return;
setIsLoading(true);
try { try {
const url = getFileUrl(editorState.src); const url = getFileUrl(editorState.src);
const request = await fetch(url, { const request = await fetch(url, {
@@ -166,6 +169,7 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} finally { } finally {
setIsLoading(false);
isDirtyRef.current = false; isDirtyRef.current = false;
isInitialLoadRef.current = true; isInitialLoadRef.current = true;
open(); open();
@@ -178,6 +182,7 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
} }
isSavingRef.current = true; isSavingRef.current = true;
setIsSaving(true);
try { try {
const { exportToSvg } = await import("@excalidraw/excalidraw"); const { exportToSvg } = await import("@excalidraw/excalidraw");
@@ -223,6 +228,7 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
isDirtyRef.current = false; isDirtyRef.current = false;
} finally { } finally {
isSavingRef.current = false; isSavingRef.current = false;
setIsSaving(false);
} }
}, [editor, excalidrawAPI, editorState?.attachmentId]); }, [editor, excalidrawAPI, editorState?.attachmentId]);
@@ -339,6 +345,7 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
size="lg" size="lg"
aria-label={t("Edit")} aria-label={t("Edit")}
variant="subtle" variant="subtle"
loading={isLoading}
> >
<IconEdit size={18} /> <IconEdit size={18} />
</ActionIcon> </ActionIcon>
@@ -390,7 +397,7 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
bg="var(--mantine-color-body)" bg="var(--mantine-color-body)"
p="xs" p="xs"
> >
<Button onClick={handleSaveAndExit} size={"compact-sm"}> <Button onClick={handleSaveAndExit} size={"compact-sm"} loading={isSaving}>
{t("Save & Exit")} {t("Save & Exit")}
</Button> </Button>
<Button onClick={handleClose} color="red" size={"compact-sm"}> <Button onClick={handleClose} color="red" size={"compact-sm"}>
@@ -52,6 +52,7 @@ export default function ExcalidrawView(props: NodeViewProps) {
const isDirtyRef = useRef(false); const isDirtyRef = useRef(false);
const isSavingRef = useRef(false); const isSavingRef = useRef(false);
const [isSaving, setIsSaving] = useState(false);
const isInitialLoadRef = useRef(true); const isInitialLoadRef = useRef(true);
const lastFingerprintRef = useRef(""); const lastFingerprintRef = useRef("");
@@ -70,6 +71,7 @@ export default function ExcalidrawView(props: NodeViewProps) {
} }
isSavingRef.current = true; isSavingRef.current = true;
setIsSaving(true);
try { try {
const { exportToSvg } = await import("@excalidraw/excalidraw"); const { exportToSvg } = await import("@excalidraw/excalidraw");
@@ -120,6 +122,7 @@ export default function ExcalidrawView(props: NodeViewProps) {
isDirtyRef.current = false; isDirtyRef.current = false;
} finally { } finally {
isSavingRef.current = false; isSavingRef.current = false;
setIsSaving(false);
} }
}, [excalidrawAPI, editor, attachmentId, updateAttributes]); }, [excalidrawAPI, editor, attachmentId, updateAttributes]);
@@ -191,7 +194,7 @@ export default function ExcalidrawView(props: NodeViewProps) {
bg="var(--mantine-color-body)" bg="var(--mantine-color-body)"
p="xs" p="xs"
> >
<Button onClick={handleSaveAndExit} size={"compact-sm"}> <Button onClick={handleSaveAndExit} size={"compact-sm"} loading={isSaving}>
{t("Save & Exit")} {t("Save & Exit")}
</Button> </Button>
<Button onClick={handleClose} color="red" size={"compact-sm"}> <Button onClick={handleClose} color="red" size={"compact-sm"}>