From 4fd63f83553624e61178e8929144fb08778f853a Mon Sep 17 00:00:00 2001 From: VictoriaShyika Date: Tue, 26 Dec 2023 13:53:24 +0200 Subject: [PATCH 1/2] added creating function --- .../hooks/useDefaultFile.tsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx b/src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx index ca1c30e2..ee51af5c 100644 --- a/src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx +++ b/src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx @@ -1,4 +1,5 @@ import { RootNodeUid } from "@_constants/main"; +import { FileActions } from "@_node/apis"; import { MainContext } from "@_redux/main"; import { setShowActionsPanel } from "@_redux/main/processor"; import { useAppState } from "@_redux/useAppState"; @@ -7,19 +8,31 @@ import { useDispatch } from "react-redux"; // import { createDefaultFile } from "../helpers/createDefaultFile"; export const useDefaultFileCreate = () => { - const { fileTree } = useAppState(); - const { fileHandlers, reloadCurrentProject } = useContext(MainContext); - const dispatch = useDispatch(); + const { project, fileTree } = useAppState(); + const { fileHandlers, triggerCurrentProjectReload } = useContext(MainContext); useEffect(() => { if ( fileTree[RootNodeUid]?.children?.length === 0 && fileHandlers[RootNodeUid] ) { + console.log("HI !!!!!!!!!!"); + // createDefaultFile(fileHandlers); - reloadCurrentProject(); - dispatch(setShowActionsPanel(true)); + (async () => + await FileActions.create({ + projectContext: project.context, + fileTree, + fileHandlers, + parentUid: RootNodeUid, + name: "index.html", + kind: "file", + }))(); + // reload the current project + triggerCurrentProjectReload(); + // reloadCurrentProject(); + // dispatch(setShowActionsPanel(true)); } }, [fileTree[RootNodeUid]?.children, fileHandlers[RootNodeUid]]); }; From 528b6d42d21423d802725f0704bb71e5669aa421 Mon Sep 17 00:00:00 2001 From: VictoriaShyika Date: Tue, 26 Dec 2023 14:58:32 +0200 Subject: [PATCH 2/2] added default file adding --- .../hooks/useDefaultFile.tsx | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx b/src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx index ee51af5c..cf3abfd2 100644 --- a/src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx +++ b/src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx @@ -1,38 +1,38 @@ import { RootNodeUid } from "@_constants/main"; import { FileActions } from "@_node/apis"; import { MainContext } from "@_redux/main"; -import { setShowActionsPanel } from "@_redux/main/processor"; import { useAppState } from "@_redux/useAppState"; -import { useContext, useEffect } from "react"; -import { useDispatch } from "react-redux"; -// import { createDefaultFile } from "../helpers/createDefaultFile"; +import { useCallback, useContext, useEffect } from "react"; export const useDefaultFileCreate = () => { - const dispatch = useDispatch(); - const { project, fileTree } = useAppState(); + const { project, fileTree, initialFileUidToOpen } = useAppState(); const { fileHandlers, triggerCurrentProjectReload } = useContext(MainContext); + const createDefaultFile = useCallback(async () => { + await FileActions.create({ + projectContext: project.context, + fileTree, + fileHandlers, + parentUid: RootNodeUid, + name: "index.html", + kind: "file", + }); + }, [project.context, fileTree, fileHandlers, RootNodeUid]); + useEffect(() => { if ( - fileTree[RootNodeUid]?.children?.length === 0 && - fileHandlers[RootNodeUid] + initialFileUidToOpen === "" && + fileHandlers[RootNodeUid] && + !Object.values(fileTree).some( + (node) => node.data.ext === "html" && node.parentUid === RootNodeUid, + ) ) { - console.log("HI !!!!!!!!!!"); - - // createDefaultFile(fileHandlers); - (async () => - await FileActions.create({ - projectContext: project.context, - fileTree, - fileHandlers, - parentUid: RootNodeUid, - name: "index.html", - kind: "file", - }))(); - // reload the current project + createDefaultFile(); triggerCurrentProjectReload(); - // reloadCurrentProject(); - // dispatch(setShowActionsPanel(true)); } - }, [fileTree[RootNodeUid]?.children, fileHandlers[RootNodeUid]]); + }, [ + fileTree[RootNodeUid]?.children, + fileHandlers[RootNodeUid], + initialFileUidToOpen, + ]); };