Skip to content

Commit

Permalink
Merge pull request #537 from VictoriaShyika/274_default_file
Browse files Browse the repository at this point in the history
274 default file
  • Loading branch information
atulbhatt-system32 authored Dec 26, 2023
2 parents 99c53c1 + 528b6d4 commit 66b5617
Showing 1 changed file with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +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 { fileTree } = useAppState();
const { fileHandlers, reloadCurrentProject } = useContext(MainContext);
const { project, fileTree, initialFileUidToOpen } = useAppState();
const { fileHandlers, triggerCurrentProjectReload } = useContext(MainContext);

const dispatch = useDispatch();
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,
)
) {
// createDefaultFile(fileHandlers);
reloadCurrentProject();
dispatch(setShowActionsPanel(true));
createDefaultFile();
triggerCurrentProjectReload();
}
}, [fileTree[RootNodeUid]?.children, fileHandlers[RootNodeUid]]);
}, [
fileTree[RootNodeUid]?.children,
fileHandlers[RootNodeUid],
initialFileUidToOpen,
]);
};

0 comments on commit 66b5617

Please sign in to comment.