From 1243e755fe5a4deecc4575c842c4cafeccc26cea Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Tue, 14 Oct 2025 15:57:03 -0700 Subject: [PATCH] Add reset ability to 2D (#874) --- .../app/src/pages/PageDraw/PageDraw.tsx | 2 +- .../src/pages/PageDraw/stores/SceneState.ts | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/frontend/apps/editor3d/app/src/pages/PageDraw/PageDraw.tsx b/frontend/apps/editor3d/app/src/pages/PageDraw/PageDraw.tsx index a4502db865..6a43936094 100644 --- a/frontend/apps/editor3d/app/src/pages/PageDraw/PageDraw.tsx +++ b/frontend/apps/editor3d/app/src/pages/PageDraw/PageDraw.tsx @@ -369,7 +369,7 @@ const PageDraw = () => { input.click(); }} onDelete={(): void => { - store.deleteSelectedItems(); + store.RESET(); }} activeToolId={store.activeTool} currentShape={store.currentShape} diff --git a/frontend/apps/editor3d/app/src/pages/PageDraw/stores/SceneState.ts b/frontend/apps/editor3d/app/src/pages/PageDraw/stores/SceneState.ts index 95b3de0f87..ef97308a6e 100644 --- a/frontend/apps/editor3d/app/src/pages/PageDraw/stores/SceneState.ts +++ b/frontend/apps/editor3d/app/src/pages/PageDraw/stores/SceneState.ts @@ -196,6 +196,7 @@ interface SceneState { // Action for deleting selected items deleteSelectedItems: () => void; + RESET: () => void; // Clipboard actions copySelectedItems: () => void; @@ -234,10 +235,8 @@ interface SceneState { sendBackward: (nodeIds: string[]) => void; // Start background removal (enqueues task with Tauri) - beginRemoveBackground: ( - nodeIds: string[], - ) => Promise; - + beginRemoveBackground: (nodeIds: string[]) => Promise; + // Finish background removal (handoff back from a Tauri-sent event) finishRemoveBackground: ( nodeId: string, @@ -273,7 +272,7 @@ const getNextZIndex = (nodes: Node[], lineNodes: LineNode[]): number => { return allZIndices.length > 0 ? Math.max(...allZIndices) + 1 : 1; }; -export const useSceneStore = create((set, get) => ({ +export const useSceneStore = create((set, get, store) => ({ // Initial state nodes: [], lineNodes: [], @@ -289,7 +288,7 @@ export const useSceneStore = create((set, get) => ({ fillColor: "white", currentShape: null, shapeColor: "#4d79b3", - + // Cursor initial state cursorPosition: null, cursorVisible: false, @@ -337,7 +336,6 @@ export const useSceneStore = create((set, get) => ({ } }, - updateNode: ( id: string, updates: Partial, @@ -838,6 +836,10 @@ export const useSceneStore = create((set, get) => ({ } }, + RESET: () => { + set(store.getInitialState()); + }, + // Clipboard actions copySelectedItems: () => { set((state) => { @@ -1437,9 +1439,7 @@ export const useSceneStore = create((set, get) => ({ }); get().saveState(); }, - beginRemoveBackground: async ( - nodeIds: string[], - ) => { + beginRemoveBackground: async (nodeIds: string[]) => { const hasImageNodes = nodeIds.some((id) => { const node = get().nodes.find((n) => n.id === id); return node ? node.type === "image" : false; @@ -1455,7 +1455,7 @@ export const useSceneStore = create((set, get) => ({ } try { const base64Image = await convertFileToBase64(firstNode.imageFile); - // NB: This handler is async, so we subscribe (externally) and + // NB: This handler is async, so we subscribe (externally) and // wait for the bg removal to complete. const _response = await EnqueueImageBgRemoval({ base64_image: base64Image,