fix: reset processed state and tool-specific stores on tool navigation

This commit is contained in:
ashim-hq
2026-04-20 21:36:14 +08:00
parent 0eeb5b07a9
commit 335e35c96a
+27 -2
View File
@@ -27,8 +27,14 @@ import { useMobile } from "@/hooks/use-mobile";
import { formatFileSize } from "@/lib/download";
import { ICON_MAP } from "@/lib/icon-map";
import { getToolRegistryEntry } from "@/lib/tool-registry";
import { useBase64Store } from "@/stores/base64-store";
import { useCollageStore } from "@/stores/collage-store";
import { useDuplicateStore } from "@/stores/duplicate-store";
import { useFeaturesStore } from "@/stores/features-store";
import { useFileStore } from "@/stores/file-store";
import { usePdfToImageStore } from "@/stores/pdf-to-image-store";
import { useQrStore } from "@/stores/qr-store";
import { useSplitStore } from "@/stores/split-store";
/** Formats that browsers can render in <img> tags. */
const BROWSER_PREVIEWABLE_EXTS = new Set([
@@ -202,11 +208,30 @@ export function ToolPage() {
// Center of the painted mask as a 0-100 percentage — used to init the slider at the right spot
const [eraserSliderInitPos, setEraserSliderInitPos] = useState<number | null>(null);
// Reset crop state when the image changes
// biome-ignore lint/correctness/useExhaustiveDependencies: toolId triggers intentional reset on tool navigation
useEffect(() => {
useFileStore.getState().undoProcessing();
useBase64Store.getState().reset();
useCollageStore.getState().reset();
useDuplicateStore.getState().reset();
usePdfToImageStore.getState().reset();
useQrStore.getState().reset();
useSplitStore.getState().reset();
setPreviewTransform(null);
setPreviewFilter("");
setImageWrapperStyle(null);
setBgPreview(null);
setCropCrop({ unit: "%", x: 0, y: 0, width: 100, height: 100 });
setCropAspect(undefined);
setCropShowGrid(true);
setCropImgDimensions(null);
}, []);
setEraserHasStrokes(false);
setEraserBrushSize(30);
setEraserSliderInitPos(null);
setMobileSettingsOpen(true);
}, [toolId]);
const handleFiles = useCallback(
(newFiles: File[]) => {