From 2337842f57ff23b8c589f8919e7da716e4bd0b90 Mon Sep 17 00:00:00 2001 From: ad1992 Date: Tue, 29 Mar 2022 16:07:45 +0530 Subject: [PATCH] fix typescript --- src/actions/actionCanvas.tsx | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index 227cd8273..510b56f1d 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -304,34 +304,42 @@ export const actionToggleTheme = register({ export const actionErase = register({ name: "eraser", trackEvent: { category: "toolbar" }, - //@ts-ignore perform: (elements, appState) => { - let lastActiveToolBeforeEraser: AppState["activeTool"]["lastActiveToolBeforeEraser"] = - undefined; + const activeTool: any = {}; if (appState.activeTool.type !== "eraser") { if (appState.activeTool.type === "custom") { - lastActiveToolBeforeEraser = { + activeTool.lastActiveToolBeforeEraser = { type: "custom", customType: appState.activeTool.customType, }; } else { - lastActiveToolBeforeEraser = appState.activeTool.type; + activeTool.lastActiveToolBeforeEraser = appState.activeTool.type; } } - + if (isEraserActive(appState)) { + if (appState.activeTool.lastActiveToolBeforeEraser) { + if ( + typeof appState.activeTool.lastActiveToolBeforeEraser === "object" && + appState.activeTool.lastActiveToolBeforeEraser?.type === "custom" + ) { + activeTool.type = "custom"; + activeTool.customType = + appState.activeTool.lastActiveToolBeforeEraser.customType; + } else { + activeTool.type = appState.activeTool.type; + } + } else { + activeTool.type = "selection"; + } + } else { + activeTool.type = "eraser"; + } return { appState: { ...appState, selectedElementIds: {}, selectedGroupIds: {}, - activeTool: { - ...appState.activeTool, - type: isEraserActive(appState) - ? appState.activeTool.lastActiveToolBeforeEraser ?? "selection" - : "eraser", - - lastActiveToolBeforeEraser, - }, + activeTool, }, commitToHistory: true, };