Skip to content

Commit

Permalink
Merge branch 'dev' into 411-delete-file
Browse files Browse the repository at this point in the history
  • Loading branch information
VictoriaShyika committed Dec 14, 2023
2 parents c503f29 + e514473 commit 75c0bc5
Show file tree
Hide file tree
Showing 39 changed files with 359 additions and 286 deletions.
3 changes: 2 additions & 1 deletion src/_node/apis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { doFileActions, doNodeActions } from "./";
import { doNodeActions } from "./node";
import { doFileActions } from "./file";

export const callNodeApi = doNodeActions;
export const callFileApi = doFileActions;
17 changes: 9 additions & 8 deletions src/_node/file/FileSystemApis.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { verifyFileHandlerPermission } from "@_services/main";

import {
_createIDBDirectory,
_getIDBDirectoryOrFileStat,
_readIDBDirectory,
_readIDBFile,
_removeIDBDirectoryOrFile,
_writeIDBFile,
getFileNameAndExtensionFromFullname,
TFileHandlerCollection,
TFileNodeData,
TFileNodeTreeData,
TNodeUid,
} from "../";
import {
_createIDBDirectory,
_getIDBDirectoryOrFileStat,
_readIDBDirectory,
_readIDBFile,
_removeIDBDirectoryOrFile,
_writeIDBFile,
_path,
} from "./nohostApis";
import { FileSystemFileHandle } from "file-system-access";

const _path = window.Filer.path;

// true: success, false: fail
const createLocalSingleDirectoryOrFile = async ({
parentUid,
Expand Down
75 changes: 10 additions & 65 deletions src/_node/file/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,29 @@ import {
} from "@_types/main";

import {
fileHandlers,
getSubNodeUidsByBfs,
TFileHandlerCollection,
TFileNode,
TFileNodeData,
TFileNodeTreeData,
TFileParserResponse,
TNodeTreeData,
TNodeUid,
TProjectLoaderResponse,
} from "../";
import { fileHandlers } from "./handlers/handlers";
import { getInitialFileUidToOpen, sortFilesByASC } from "./helpers";
import { TFileHandlerInfo, TFileHandlerInfoObj, TZipFileInfo } from "./types";
import { FileSystemFileHandle } from "file-system-access";

export const _fs = window.Filer.fs;
export const _path = window.Filer.path;
export const _sh = new _fs.Shell();
import {
_createIDBDirectory,
_getIDBDirectoryOrFileStat,
_readIDBDirectory,
_readIDBFile,
_removeIDBDirectoryOrFile,
_writeIDBFile,
_path,
} from "./nohostApis";

export const initIDBProject = async (projectPath: string): Promise<void> => {
return new Promise<void>(async (resolve, reject) => {
Expand Down Expand Up @@ -470,66 +475,6 @@ export const downloadIDBProject = async (
});
};

export const _createIDBDirectory = async (path: string): Promise<void> => {
return new Promise<void>((resolve, reject) => {
_fs.mkdir(path, (err: any) => {
err ? reject(err) : resolve();
});
});
};
export const _readIDBFile = async (path: string): Promise<Uint8Array> => {
return new Promise<Uint8Array>((resolve, reject) => {
_fs.readFile(path, (err: any, data: Buffer) => {
err ? reject(err) : resolve(data);
});
});
};
export const _writeIDBFile = async (
path: string,
content: Uint8Array | string,
): Promise<void> => {
return new Promise<void>((resolve, reject) => {
_fs.writeFile(path, content, (err: any) => {
err ? reject(err) : resolve();
});
});
};
export const _removeIDBDirectoryOrFile = async (
path: string,
): Promise<void> => {
return new Promise<void>((resolve, reject) => {
_sh.rm(path, { recursive: true }, (err: any) => {
err ? reject(err) : resolve();
});
});
};
export const _readIDBDirectory = async (path: string): Promise<string[]> => {
return new Promise<string[]>((resolve, reject) => {
_fs.readdir(path, (err: any, files: string[]) => {
err ? reject(err) : resolve(files);
});
});
};
export const _getIDBDirectoryOrFileStat = async (
path: string,
): Promise<any> => {
return new Promise<any>((resolve, reject) => {
_fs.stat(path, (err: any, stats: any) => {
err ? reject(err) : resolve(stats);
});
});
};

export const getNormalizedPath = (
path: string,
): { isAbsolutePath: boolean; normalizedPath: string } => {
if (path.startsWith("https://") || path.startsWith("http://")) {
return { isAbsolutePath: true, normalizedPath: path };
}
const isAbsolutePath = _path.isAbsolute(path);
const normalizedPath = _path.normalize(path);
return { isAbsolutePath, normalizedPath };
};
export const parseFile = (
ext: string,
content: string,
Expand Down
15 changes: 11 additions & 4 deletions src/_node/file/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TFileNodeData,
TFileNodeTreeData,
TNodeUid,
_path,
} from "../";

export const sortFilesByASC = (handlerObj: TFileHandlerInfoObj) => {
Expand All @@ -22,7 +23,6 @@ export const sortFilesByASC = (handlerObj: TFileHandlerInfoObj) => {
});
});
};

export const getInitialFileUidToOpen = (handlerObj: TFileHandlerInfoObj) => {
let firstHtmlUid: TNodeUid = "",
indexHtmlUid: TNodeUid = "",
Expand All @@ -46,7 +46,6 @@ export const getInitialFileUidToOpen = (handlerObj: TFileHandlerInfoObj) => {

return initialFileUidToOpen;
};

export const isUnsavedProject = (fileTree: TFileNodeTreeData) => {
for (const uid in fileTree) {
const file = fileTree[uid];
Expand All @@ -57,7 +56,6 @@ export const isUnsavedProject = (fileTree: TFileNodeTreeData) => {
}
return false;
};

export const confirmAlert = (msg: string): boolean => {
if (!window.confirm(msg)) {
return false;
Expand All @@ -69,7 +67,6 @@ export const confirmFileChanges = (fileTree: TFileNodeTreeData): boolean => {
? confirmAlert(FileChangeAlertMessage)
: true;
};

export const getFileNameAndExtensionFromFullname = (
name: string,
): { baseName: string; ext: string } => {
Expand All @@ -78,3 +75,13 @@ export const getFileNameAndExtensionFromFullname = (
const baseName = nameArr.join(".");
return { baseName, ext };
};
export const getNormalizedPath = (
path: string,
): { isAbsolutePath: boolean; normalizedPath: string } => {
if (path.startsWith("https://") || path.startsWith("http://")) {
return { isAbsolutePath: true, normalizedPath: path };
}
const isAbsolutePath = _path.isAbsolute(path);
const normalizedPath = _path.normalize(path);
return { isAbsolutePath, normalizedPath };
};
2 changes: 2 additions & 0 deletions src/_node/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export * from "./apis";
export * from "./helpers";
export * from "./actions";
export * from "./handlers";
export * from "./FileSystemApis";
export * from "./nohostApis";
55 changes: 55 additions & 0 deletions src/_node/file/nohostApis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Buffer } from "buffer";

export const _fs = window.Filer.fs;
export const _path = window.Filer.path;
export const _sh = new _fs.Shell();

export const _createIDBDirectory = async (path: string): Promise<void> => {
return new Promise<void>((resolve, reject) => {
_fs.mkdir(path, (err: any) => {
err ? reject(err) : resolve();
});
});
};
export const _readIDBFile = async (path: string): Promise<Uint8Array> => {
return new Promise<Uint8Array>((resolve, reject) => {
_fs.readFile(path, (err: any, data: Buffer) => {
err ? reject(err) : resolve(data);
});
});
};
export const _writeIDBFile = async (
path: string,
content: Uint8Array | string,
): Promise<void> => {
return new Promise<void>((resolve, reject) => {
_fs.writeFile(path, content, (err: any) => {
err ? reject(err) : resolve();
});
});
};
export const _removeIDBDirectoryOrFile = async (
path: string,
): Promise<void> => {
return new Promise<void>((resolve, reject) => {
_sh.rm(path, { recursive: true }, (err: any) => {
err ? reject(err) : resolve();
});
});
};
export const _readIDBDirectory = async (path: string): Promise<string[]> => {
return new Promise<string[]>((resolve, reject) => {
_fs.readdir(path, (err: any, files: string[]) => {
err ? reject(err) : resolve(files);
});
});
};
export const _getIDBDirectoryOrFileStat = async (
path: string,
): Promise<any> => {
return new Promise<any>((resolve, reject) => {
_fs.stat(path, (err: any, stats: any) => {
err ? reject(err) : resolve(stats);
});
});
};
2 changes: 1 addition & 1 deletion src/_node/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
} from "@_constants/main";
import { THtmlReferenceData } from "@_types/main";

import { THtmlNodeData } from "./node";
import {
TBasicNodeData,
TNode,
TNodeReferenceData,
TNodeTreeData,
TNodeUid,
} from "./types";
import { THtmlNodeData } from "./node";

export const getSubNodeUidsByBfs = (
uid: TNodeUid,
Expand Down
2 changes: 1 addition & 1 deletion src/_node/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./apis";
export * from "./types";
export * from "./helpers";
export * from "./apis";
export * from "./file";
export * from "./node";
1 change: 0 additions & 1 deletion src/_node/node/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ const ungroup = ({
});
addedChildCount[parentNode.uid] += containerNode.children.length - 1;
});
console.log(needToSelectNodePaths);
return needToSelectNodePaths;
})();
return needToSelectNodePaths;
Expand Down
9 changes: 8 additions & 1 deletion src/_redux/main/codeView/slice.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";

import { TCodeViewReducerState } from "./types";
import { TNodeUid } from "@_node/types";

const codeViewReducerInitialState: TCodeViewReducerState = {
editingNodeUid: null,
codeViewTabSize: 4,
};
const codeViewSlice = createSlice({
name: "codeView",
initialState: codeViewReducerInitialState,
reducers: {
setEditingNodeUidInCodeView(state, action: PayloadAction<TNodeUid | null>) {
const editingNodeUid = action.payload;
state.editingNodeUid = editingNodeUid;
},
setCodeViewTabSize(state, action: PayloadAction<number>) {
const codeViewTabSize = action.payload;
state.codeViewTabSize = codeViewTabSize;
},
},
});
export const { setCodeViewTabSize } = codeViewSlice.actions;
export const { setEditingNodeUidInCodeView, setCodeViewTabSize } =
codeViewSlice.actions;
export const CodeViewReduer = codeViewSlice.reducer;
3 changes: 3 additions & 0 deletions src/_redux/main/codeView/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { TNodeUid } from "@_node/types";

export type TCodeViewReducerState = {
editingNodeUid: TNodeUid | null;
codeViewTabSize: number;
};
4 changes: 4 additions & 0 deletions src/_redux/main/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const MainContext: Context<TMainContext> = createContext<TMainContext>({
current: false,
},
setIsContentProgrammaticallyChanged: () => {},
isCodeTyping: {
current: false,
},
setIsCodeTyping: () => {},

importProject: () => {},
onUndo: () => {},
Expand Down
11 changes: 9 additions & 2 deletions src/_redux/main/nodeTree/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";

import { TUpdateTreeViewStatePayload } from "../types";
import { TNodeTreeReducerState } from "./types";
import { TCodeSelection } from "@_components/main/codeView";

const nodeTreeReducerInitialState: TNodeTreeReducerState = {
nodeTree: {},
validNodeTree: {},

needToSelectNodePaths: [],
needToSelectNodePaths: null,
needToSelectCode: null,

nodeTreeViewState: {
focusedItem: "",
Expand All @@ -32,10 +34,14 @@ const nodeTreeSlice = createSlice({
state.validNodeTree = validNodeTree;
},

setNeedToSelectNodePaths(state, action: PayloadAction<string[]>) {
setNeedToSelectNodePaths(state, action: PayloadAction<string[] | null>) {
const needToSelectNodePaths = action.payload;
state.needToSelectNodePaths = needToSelectNodePaths;
},
setNeedToSelectCode(state, action: PayloadAction<TCodeSelection | null>) {
const needToSelectCode = action.payload;
state.needToSelectCode = needToSelectCode;
},

focusNodeTreeNode(state, action: PayloadAction<TNodeUid>) {
const focusedItem = action.payload;
Expand Down Expand Up @@ -146,6 +152,7 @@ export const {
setValidNodeTree,

setNeedToSelectNodePaths,
setNeedToSelectCode,

focusNodeTreeNode,
setExpandedNodeTreeNodes,
Expand Down
4 changes: 3 additions & 1 deletion src/_redux/main/nodeTree/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { TNodeTreeData, TNodeUid } from "@_node/types";

import { TTreeViewState } from "../types";
import { TCodeSelection } from "@_components/main/codeView";

export type TNodeTreeReducerState = {
nodeTree: TNodeTreeData;
validNodeTree: TNodeTreeData;

needToSelectNodePaths: string[];
needToSelectNodePaths: string[] | null;
needToSelectCode: TCodeSelection | null;

nodeTreeViewState: TTreeViewState;
hoveredNodeUid: TNodeUid;
Expand Down
2 changes: 2 additions & 0 deletions src/_redux/main/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export type TMainContext = {
setIframeRefRef: (iframeRef: HTMLIFrameElement | null) => void;
isContentProgrammaticallyChanged: React.RefObject<boolean>;
setIsContentProgrammaticallyChanged: (value: boolean) => void;
isCodeTyping: React.RefObject<boolean>;
setIsCodeTyping: (value: boolean) => void;

importProject: (
fsType: TProjectContext,
Expand Down
Loading

0 comments on commit 75c0bc5

Please sign in to comment.