Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #515

Merged
merged 7 commits into from
Dec 14, 2023
Merged

Dev #515

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
};