Skip to content

Commit

Permalink
feat: reset copyStatus on export dialog settings change (excalidraw#8443
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dwelle authored Aug 29, 2024
1 parent 576bc0d commit 16cae4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/excalidraw/components/ImageExportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,20 @@ const ImageExportModal = ({
const previewRef = useRef<HTMLDivElement>(null);
const [renderError, setRenderError] = useState<Error | null>(null);

const { onCopy, copyStatus } = useCopyStatus();
const { onCopy, copyStatus, resetCopyStatus } = useCopyStatus();

useEffect(() => {
// if user changes setting right after export to clipboard, reset the status
// so they don't have to wait for the timeout to click the button again
resetCopyStatus();
}, [
projectName,
exportWithBackground,
exportDarkMode,
exportScale,
embedScene,
resetCopyStatus,
]);

const { exportedElements, exportingFrame } = prepareElementsForExport(
elementsSnapshot,
Expand All @@ -108,6 +121,7 @@ const ImageExportModal = ({
if (!maxWidth) {
return;
}

exportToCanvas({
elements: exportedElements,
appState: {
Expand Down
7 changes: 6 additions & 1 deletion packages/excalidraw/hooks/useCopiedIndicator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from "react";
import { useCallback, useRef, useState } from "react";

const TIMEOUT = 2000;

Expand All @@ -15,8 +15,13 @@ export const useCopyStatus = () => {
}, TIMEOUT);
};

const resetCopyStatus = useCallback(() => {
setCopyStatus(null);
}, []);

return {
copyStatus,
resetCopyStatus,
onCopy,
};
};

0 comments on commit 16cae4f

Please sign in to comment.