Skip to content

Commit

Permalink
Refactor file and node actions
Browse files Browse the repository at this point in the history
  • Loading branch information
atulbhatt-system32 committed Dec 22, 2023
1 parent c974df6 commit 5c94402
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
7 changes: 3 additions & 4 deletions src/_node/apis.ts
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 1 addition & 1 deletion src/_node/file/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const rename = async ({
}
};

export const doFileActions = {
export const FileActions = {
create,
remove,
rename,
Expand Down
2 changes: 1 addition & 1 deletion src/_node/node/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -43,7 +42,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "add",
Expand Down Expand Up @@ -72,7 +71,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "cut",
Expand All @@ -97,7 +96,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "copy",
Expand Down Expand Up @@ -127,7 +126,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "paste",
Expand All @@ -152,7 +151,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "remove",
Expand All @@ -177,7 +176,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "duplicate",
Expand Down Expand Up @@ -211,7 +210,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "move",
Expand Down Expand Up @@ -243,7 +242,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "rename",
Expand Down Expand Up @@ -272,7 +271,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "group",
Expand All @@ -297,7 +296,7 @@ export const useNodeActionHandlers = () => {
}

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "ungroup",
Expand Down
4 changes: 2 additions & 2 deletions src/components/main/stageView/iFrame/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { editor } from "monaco-editor";

import {
callNodeApi,
NodeActions,
StageNodeIdAttr,
TNodeTreeData,
TNodeUid,
Expand Down Expand Up @@ -119,7 +119,7 @@ export const editHtmlContent = ({
const content = contentEditableElement.textContent;

setIsContentProgrammaticallyChanged(true);
callNodeApi(
NodeActions(
{
dispatch,
action: "text-edit",
Expand Down
6 changes: 3 additions & 3 deletions src/pages/main/processor/hooks/useNodeTreeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 5c94402

Please sign in to comment.