From 5c944024e6b4aec1280cdd3c63978b30608a1897 Mon Sep 17 00:00:00 2001 From: Atul Bhatt <38177419+atulbhatt-system32@users.noreply.github.com> Date: Fri, 22 Dec 2023 17:53:21 +0530 Subject: [PATCH] Refactor file and node actions --- src/_node/apis.ts | 7 +++--- src/_node/file/actions.ts | 2 +- src/_node/node/actions.ts | 2 +- .../hooks/useNodeActionHandlers.ts | 23 +++++++++---------- .../main/stageView/iFrame/helpers.ts | 4 ++-- .../main/processor/hooks/useNodeTreeEvent.ts | 6 ++--- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/_node/apis.ts b/src/_node/apis.ts index 87477350..0f17603d 100644 --- a/src/_node/apis.ts +++ b/src/_node/apis.ts @@ -1,5 +1,4 @@ -import { doFileActions } from "./file"; -import { doNodeActions } from "./node"; +import { FileActions } from "./file"; +import { NodeActions } from "./node"; -export const callNodeApi = doNodeActions; -export const FileActions = doFileActions; +export { FileActions, NodeActions }; diff --git a/src/_node/file/actions.ts b/src/_node/file/actions.ts index ed1bcb46..9ade007f 100644 --- a/src/_node/file/actions.ts +++ b/src/_node/file/actions.ts @@ -111,7 +111,7 @@ const rename = async ({ } }; -export const doFileActions = { +export const FileActions = { create, remove, rename, diff --git a/src/_node/node/actions.ts b/src/_node/node/actions.ts index 524f8d68..c08f39d5 100644 --- a/src/_node/node/actions.ts +++ b/src/_node/node/actions.ts @@ -556,7 +556,7 @@ const edit = ({ return needToSelectNodePaths; }; -export const doNodeActions = async ( +export const NodeActions = async ( params: TNodeApiPayload, fb?: (...params: any[]) => void, cb?: (...params: any[]) => void, diff --git a/src/components/main/actionsPanel/nodeTreeView/hooks/useNodeActionHandlers.ts b/src/components/main/actionsPanel/nodeTreeView/hooks/useNodeActionHandlers.ts index 580d3980..0ea1368c 100644 --- a/src/components/main/actionsPanel/nodeTreeView/hooks/useNodeActionHandlers.ts +++ b/src/components/main/actionsPanel/nodeTreeView/hooks/useNodeActionHandlers.ts @@ -6,8 +6,7 @@ import { LogAllow } from "@_constants/global"; import { TNodeUid } from "@_node/types"; import { MainContext } from "@_redux/main"; import { useAppState } from "@_redux/useAppState"; -import { doNodeActions } from "@_node/node"; -import { callNodeApi } from "@_node/apis"; +import { NodeActions } from "@_node/apis"; export const useNodeActionHandlers = () => { const dispatch = useDispatch(); @@ -43,7 +42,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "add", @@ -72,7 +71,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "cut", @@ -97,7 +96,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "copy", @@ -127,7 +126,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "paste", @@ -152,7 +151,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "remove", @@ -177,7 +176,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "duplicate", @@ -211,7 +210,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "move", @@ -243,7 +242,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "rename", @@ -272,7 +271,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "group", @@ -297,7 +296,7 @@ export const useNodeActionHandlers = () => { } setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "ungroup", diff --git a/src/components/main/stageView/iFrame/helpers.ts b/src/components/main/stageView/iFrame/helpers.ts index 16dbad3b..d03a240e 100644 --- a/src/components/main/stageView/iFrame/helpers.ts +++ b/src/components/main/stageView/iFrame/helpers.ts @@ -1,7 +1,7 @@ import { editor } from "monaco-editor"; import { - callNodeApi, + NodeActions, StageNodeIdAttr, TNodeTreeData, TNodeUid, @@ -119,7 +119,7 @@ export const editHtmlContent = ({ const content = contentEditableElement.textContent; setIsContentProgrammaticallyChanged(true); - callNodeApi( + NodeActions( { dispatch, action: "text-edit", diff --git a/src/pages/main/processor/hooks/useNodeTreeEvent.ts b/src/pages/main/processor/hooks/useNodeTreeEvent.ts index 1b866d07..57605708 100644 --- a/src/pages/main/processor/hooks/useNodeTreeEvent.ts +++ b/src/pages/main/processor/hooks/useNodeTreeEvent.ts @@ -265,8 +265,8 @@ export const useNodeTreeEvent = () => { if (needToSelectNodePaths) { LogAllow && console.log("it's a rnbw-change from node-actions"); - // this means we called `callNodeApi` and we need to select predicted `needToSelectNodeUids` - // in the case, `callNodeApi -> setCurrentFileContent` and `setNeedToSelectNodeUids` dispatch actions are considered as an one event in the node-event-history. + // this means we called `NodeActions` and we need to select predicted `needToSelectNodeUids` + // in the case, `NodeActions -> setCurrentFileContent` and `setNeedToSelectNodeUids` dispatch actions are considered as an one event in the node-event-history. const needToSelectNodeUids = getNodeUidsFromPaths( _validNodeTree, needToSelectNodePaths, @@ -277,7 +277,7 @@ export const useNodeTreeEvent = () => { } else if (needToSelectCode) { LogAllow && console.log("it's a rnbw-change from code-view"); // it's a typing change in code-view and we need to select currently `cursored node` in code-view. - // in the case, `callNodeApi -> setCurrentFileContent` and `setNeedToSelectNodeUids` dispatch actions are considered as an one event in the node-event-history. + // in the case, `NodeActions -> setCurrentFileContent` and `setNeedToSelectNodeUids` dispatch actions are considered as an one event in the node-event-history. const needToSelectNodeUid = getNodeUidByCodeSelection( needToSelectCode, nodeTree,