diff --git a/src/_node/file/apis.ts b/src/_node/file/apis.ts index c93ae916..84416e46 100644 --- a/src/_node/file/apis.ts +++ b/src/_node/file/apis.ts @@ -327,9 +327,11 @@ export const loadLocalProject = async ( // sort by ASC directory/file sortFilesByASC(handlerObj); // define the initialFileUidToOpen - let _initialFileUidToOpen: TNodeUid = isReload - ? "" - : getInitialFileUidToOpen(handlerObj); + let _initialFileUidToOpen: TNodeUid = + // isReload + // ? "" + // : + getInitialFileUidToOpen(handlerObj); // build fileTree and fileHandlers const _fileTree: TFileNodeTreeData = {}; diff --git a/src/_redux/main/context.ts b/src/_redux/main/context.ts index a185d85b..ad8f68ee 100644 --- a/src/_redux/main/context.ts +++ b/src/_redux/main/context.ts @@ -33,6 +33,7 @@ export const MainContext: Context = createContext({ setIsCodeTyping: () => {}, importProject: () => {}, + reloadCurrentProject: () => {}, onUndo: () => {}, onRedo: () => {}, }); diff --git a/src/_redux/main/types.ts b/src/_redux/main/types.ts index b81adda7..900878ee 100644 --- a/src/_redux/main/types.ts +++ b/src/_redux/main/types.ts @@ -2,7 +2,7 @@ import { MutableRefObject } from "react"; import { editor } from "monaco-editor"; -import { TFileHandlerCollection } from "@_node/file"; +import { TFileHandlerCollection, TFileNodeTreeData } from "@_node/file"; import { TNodeUid } from "@_node/types"; import { TCmdkReferenceData, @@ -65,6 +65,11 @@ export type TMainContext = { fsType: TProjectContext, projectHandle?: FileSystemDirectoryHandle | null, ) => void; + reloadCurrentProject: ( + fileTree: TFileNodeTreeData, + currentProjectFileHandle: FileSystemDirectoryHandle | null, + ) => void; + onUndo: () => void; onRedo: () => void; }; diff --git a/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts b/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts index 4199e0cb..6db9f00e 100644 --- a/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts +++ b/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts @@ -14,6 +14,7 @@ import { TFileNodeData, _writeIDBFile, confirmAlert, + loadLocalProject, } from "@_node/file"; import { getValidNodeUids } from "@_node/helpers"; import { TNode, TNodeTreeData, TNodeUid } from "@_node/types"; @@ -82,6 +83,8 @@ export const useNodeActionsHandler = ({ removeRunningActions, fileHandlers, htmlReferenceData, + currentProjectFileHandle, + reloadCurrentProject, } = useContext(MainContext); const createFFNode = useCallback( @@ -324,6 +327,7 @@ export const useNodeActionsHandler = ({ LogAllow && console.error("error while removing file system"); }, (allDone: boolean) => { + reloadCurrentProject(fileTree, currentProjectFileHandle); LogAllow && console.log( allDone ? "all is successfully removed" : "some is not removed", diff --git a/src/pages/main/MainPage.tsx b/src/pages/main/MainPage.tsx index c1e09699..18dec8cc 100644 --- a/src/pages/main/MainPage.tsx +++ b/src/pages/main/MainPage.tsx @@ -104,7 +104,7 @@ export default function MainPage() { htmlReferenceData, }); - const { importProject, closeNavigator } = useHandlers({ + const { importProject, closeNavigator, reloadCurrentProject } = useHandlers({ setCurrentProjectFileHandle, setFileHandlers, @@ -194,6 +194,7 @@ export default function MainPage() { setIsCodeTyping, importProject, + reloadCurrentProject, onUndo, onRedo, }} diff --git a/src/pages/main/hooks/useHandlers.ts b/src/pages/main/hooks/useHandlers.ts index 64f18015..16d371f2 100644 --- a/src/pages/main/hooks/useHandlers.ts +++ b/src/pages/main/hooks/useHandlers.ts @@ -9,6 +9,7 @@ import { loadIDBProject, loadLocalProject, TFileHandlerCollection, + TFileNodeTreeData, } from "@_node/file"; import { setDoingFileAction, @@ -180,12 +181,26 @@ export const useHandlers = ({ }, [osType, saveRecentProject], ); + const reloadCurrentProject = async ( + fileTree: TFileNodeTreeData, + currentProjectFileHandle: FileSystemDirectoryHandle | null, + ) => { + const { _fileTree, _initialFileUidToOpen } = await loadLocalProject( + currentProjectFileHandle as FileSystemDirectoryHandle, + osType, + true, + fileTree, + ); + dispatch(setFileTree(_fileTree)); + dispatch(setInitialFileUidToOpen(_initialFileUidToOpen)); + }; const closeNavigator = useCallback(() => { navigatorDropdownType !== null && dispatch(setNavigatorDropdownType(null)); }, [navigatorDropdownType]); return { importProject, + reloadCurrentProject, closeNavigator, }; };