From d22eac55e7a3a0340e0c23f9ca2375db0939cc52 Mon Sep 17 00:00:00 2001 From: VictoriaShyika Date: Sat, 9 Dec 2023 15:46:20 +0200 Subject: [PATCH 1/4] fixed deleting file logic --- .../helpers/validateAndDeleteNode.ts | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/main/actionsPanel/workspaceTreeView/helpers/validateAndDeleteNode.ts b/src/components/main/actionsPanel/workspaceTreeView/helpers/validateAndDeleteNode.ts index 209b31a3..ef2d15b5 100644 --- a/src/components/main/actionsPanel/workspaceTreeView/helpers/validateAndDeleteNode.ts +++ b/src/components/main/actionsPanel/workspaceTreeView/helpers/validateAndDeleteNode.ts @@ -1,11 +1,17 @@ -import { TFileHandlerCollection, TFileNodeData } from "@_node/file"; -import { TNodeTreeData, TNodeUid } from "@_node/types"; +import { + TFileHandlerCollection, + TFileNodeData, + TFileNodeTreeData, +} from "@_node/file"; +import { TNodeUid } from "@_node/types"; +import { setFileTree } from "@_redux/main/fileTree"; import { verifyFileHandlerPermission } from "@_services/main"; export const validateAndDeleteNode = async ( uid: string, - ffTree: TNodeTreeData, + ffTree: TFileNodeTreeData, fileHandlers: TFileHandlerCollection, + dispatch?: any, ) => { const node = ffTree[uid]; @@ -32,9 +38,15 @@ export const validateAndDeleteNode = async ( const entryName = nodeData.kind === "directory" ? nodeData.name - : `${nodeData.name}${nodeData.ext}`; + : `${nodeData.name}.${nodeData.ext}`; + await parentHandler.removeEntry(entryName, { recursive: true }); - return true; + + // const _ffTree = structuredClone(ffTree); + // delete _ffTree[uid]; + + // dispatch(setFileTree(_ffTree)); + // return true; } catch (err) { return false; } From 0c126c043b3c22faf119ee3e8bcf3a25fd067295 Mon Sep 17 00:00:00 2001 From: VictoriaShyika Date: Mon, 11 Dec 2023 14:03:57 +0200 Subject: [PATCH 2/4] work tree show correct files node --- .../helpers/validateAndDeleteNode.ts | 12 +----------- .../hooks/useNodeActionsHandler.ts | 16 +++++++++++----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/components/main/actionsPanel/workspaceTreeView/helpers/validateAndDeleteNode.ts b/src/components/main/actionsPanel/workspaceTreeView/helpers/validateAndDeleteNode.ts index ef2d15b5..b992766c 100644 --- a/src/components/main/actionsPanel/workspaceTreeView/helpers/validateAndDeleteNode.ts +++ b/src/components/main/actionsPanel/workspaceTreeView/helpers/validateAndDeleteNode.ts @@ -4,24 +4,19 @@ import { TFileNodeTreeData, } from "@_node/file"; import { TNodeUid } from "@_node/types"; -import { setFileTree } from "@_redux/main/fileTree"; import { verifyFileHandlerPermission } from "@_services/main"; export const validateAndDeleteNode = async ( uid: string, ffTree: TFileNodeTreeData, fileHandlers: TFileHandlerCollection, - dispatch?: any, ) => { const node = ffTree[uid]; - if (node === undefined) { return false; } - const nodeData = node.data as TFileNodeData; const parentNode = ffTree[node.parentUid as TNodeUid]; - if (parentNode === undefined) { return false; } @@ -29,7 +24,6 @@ export const validateAndDeleteNode = async ( const parentHandler = fileHandlers[ parentNode.uid ] as FileSystemDirectoryHandle; - if (!(await verifyFileHandlerPermission(parentHandler))) { return false; } @@ -42,11 +36,7 @@ export const validateAndDeleteNode = async ( await parentHandler.removeEntry(entryName, { recursive: true }); - // const _ffTree = structuredClone(ffTree); - // delete _ffTree[uid]; - - // dispatch(setFileTree(_ffTree)); - // return true; + return true; } catch (err) { return false; } diff --git a/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts b/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts index 71dc66b7..5b5bdb75 100644 --- a/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts +++ b/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts @@ -6,6 +6,7 @@ import { useDispatch } from "react-redux"; import { RednerableFileTypes, RootNodeUid, TmpNodeUid } from "@_constants/main"; import { createDirectory, + loadLocalProject, TFileNodeData, triggerFileChangeAlert, writeFile, @@ -20,11 +21,7 @@ import { setPrevRenderableFileUid, } from "@_redux/main/fileTree"; import { setFileAction, TFileAction } from "@_redux/main/fileTree/event"; -import { clearNodeTreeViewState } from "@_redux/main/nodeTree"; -import { - NodeTree_Event_ClearActionType, - setCurrentFileContent, -} from "@_redux/main/nodeTree/event"; +import { setCurrentFileContent } from "@_redux/main/nodeTree/event"; import { setNavigatorDropdownType, setShowCodeView, @@ -63,6 +60,7 @@ export const useNodeActionsHandler = ( removeRunningActions, fileHandlers, htmlReferenceData, + currentProjectFileHandle, } = useContext(MainContext); const { removeInvalidNodes, setInvalidNodes, invalidNodes } = @@ -320,6 +318,13 @@ export const useNodeActionsHandler = ( } removeInvalidNodes(...uids); + const { _fileTree } = await loadLocalProject( + currentProjectFileHandle as FileSystemDirectoryHandle, + osType, + true, + fileTree, + ); + dispatch(setFileTree(_fileTree)); removeRunningActions(["fileTreeView-delete"]); }, [ addRunningActions, @@ -331,6 +336,7 @@ export const useNodeActionsHandler = ( project.context, fileTree, fileHandlers, + currentProjectFileHandle, currentFileUid, ]); From c503f29c961301d0eb38b83d5970bd38bfc8be81 Mon Sep 17 00:00:00 2001 From: VictoriaShyika Date: Thu, 14 Dec 2023 01:28:26 +0200 Subject: [PATCH 3/4] fixed import --- .../workspaceTreeView/hooks/useNodeActionsHandler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts b/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts index ffe58f86..036c90a7 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"; From f11780e249f72fb3df09732e108b426e7fbc9712 Mon Sep 17 00:00:00 2001 From: VictoriaShyika Date: Thu, 14 Dec 2023 18:17:29 +0200 Subject: [PATCH 4/4] added reloadCurrentProject func --- src/_node/file/apis.ts | 8 +++++--- src/_redux/main/context.ts | 1 + src/_redux/main/types.ts | 7 ++++++- .../hooks/useNodeActionsHandler.ts | 9 ++------- src/pages/main/MainPage.tsx | 3 ++- src/pages/main/hooks/useHandlers.ts | 15 +++++++++++++++ 6 files changed, 31 insertions(+), 12 deletions(-) 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 0a7872bc..6db9f00e 100644 --- a/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts +++ b/src/components/main/actionsPanel/workspaceTreeView/hooks/useNodeActionsHandler.ts @@ -84,6 +84,7 @@ export const useNodeActionsHandler = ({ fileHandlers, htmlReferenceData, currentProjectFileHandle, + reloadCurrentProject, } = useContext(MainContext); const createFFNode = useCallback( @@ -326,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", @@ -333,13 +335,6 @@ export const useNodeActionsHandler = ({ }, ); removeInvalidNodes(...uids); - const { _fileTree } = await loadLocalProject( - currentProjectFileHandle as FileSystemDirectoryHandle, - osType, - true, - fileTree, - ); - dispatch(setFileTree(_fileTree)); removeRunningActions(["fileTreeView-delete"]); }, [ selectedItems, 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, }; };