Skip to content

Commit

Permalink
Merge pull request #515 from rnbwdev/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mrmatthewnguyen105 authored Dec 14, 2023
2 parents 62045ea + 8bfb818 commit 59bdc9e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/_node/file/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
1 change: 1 addition & 0 deletions src/_redux/main/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const MainContext: Context<TMainContext> = createContext<TMainContext>({
setIsCodeTyping: () => {},

importProject: () => {},
reloadCurrentProject: () => {},
onUndo: () => {},
onRedo: () => {},
});
7 changes: 6 additions & 1 deletion src/_redux/main/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,6 +65,11 @@ export type TMainContext = {
fsType: TProjectContext,
projectHandle?: FileSystemDirectoryHandle | null,
) => void;
reloadCurrentProject: (
fileTree: TFileNodeTreeData,
currentProjectFileHandle: FileSystemDirectoryHandle | null,
) => void;

onUndo: () => void;
onRedo: () => void;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TFileNodeData,
_writeIDBFile,
confirmAlert,
loadLocalProject,
} from "@_node/file";
import { getValidNodeUids } from "@_node/helpers";
import { TNode, TNodeTreeData, TNodeUid } from "@_node/types";
Expand Down Expand Up @@ -82,6 +83,8 @@ export const useNodeActionsHandler = ({
removeRunningActions,
fileHandlers,
htmlReferenceData,
currentProjectFileHandle,
reloadCurrentProject,
} = useContext(MainContext);

const createFFNode = useCallback(
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/pages/main/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function MainPage() {

htmlReferenceData,
});
const { importProject, closeNavigator } = useHandlers({
const { importProject, closeNavigator, reloadCurrentProject } = useHandlers({
setCurrentProjectFileHandle,
setFileHandlers,

Expand Down Expand Up @@ -194,6 +194,7 @@ export default function MainPage() {
setIsCodeTyping,

importProject,
reloadCurrentProject,
onUndo,
onRedo,
}}
Expand Down
15 changes: 15 additions & 0 deletions src/pages/main/hooks/useHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
loadIDBProject,
loadLocalProject,
TFileHandlerCollection,
TFileNodeTreeData,
} from "@_node/file";
import {
setDoingFileAction,
Expand Down Expand Up @@ -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,
};
};

0 comments on commit 59bdc9e

Please sign in to comment.