-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fd63f8
commit 528b6d4
Showing
1 changed file
with
24 additions
and
24 deletions.
There are no files selected for viewing
48 changes: 24 additions & 24 deletions
48
src/components/main/actionsPanel/workspaceTreeView/hooks/useDefaultFile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
]); | ||
}; |