Skip to content

Commit

Permalink
Merge pull request #509 from rnbwdev/#505
Browse files Browse the repository at this point in the history
  • Loading branch information
VictoriaShyika authored Dec 13, 2023
2 parents 7b4da45 + e5de9df commit d134d40
Show file tree
Hide file tree
Showing 59 changed files with 2,497 additions and 1,938 deletions.
442 changes: 442 additions & 0 deletions src/_node/file/FileSystemApis.ts

Large diffs are not rendered by default.

128 changes: 85 additions & 43 deletions src/_node/file/actions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
import { LogAllow } from "@_constants/global";

import { TFileApiPayload } from "../";
import {
TFileApiPayload,
TFileHandlerCollection,
TFileNodeTreeData,
TNodeUid,
} from "../";
import { TProjectContext } from "@_redux/main/fileTree";
import { FileSystemApis } from "./FileSystemApis";

const add = () => {};
const remove = () => {};
const create = () => {};
const remove = async ({
projectContext,
uids,
fileTree,
fileHandlers,
}: {
projectContext: TProjectContext;
uids: TNodeUid[];
fileTree: TFileNodeTreeData;
fileHandlers?: TFileHandlerCollection;
}): Promise<boolean> => {
return new Promise<boolean>((resolve, reject) => {
try {
let allDone = true;
uids.map((uid) => {
const done = FileSystemApis[projectContext].removeSingleDirectoryOrFile(
{
uid,
fileTree,
fileHandlers: fileHandlers || {},
},
);
if (!done) allDone = false;
});
resolve(allDone);
} catch (err) {
reject(err);
}
});
};
const cut = () => {};
const copy = () => {};
const paste = () => {};
const duplicate = () => {};
const move = () => {};
const rename = () => {};
Expand All @@ -15,45 +50,52 @@ export const doFileActions = async (
params: TFileApiPayload,
fb?: (...params: any[]) => void,
cb?: (...params: any[]) => void,
): Promise<void> => {
return new Promise((resolve, reject) => {
try {
const { action, osType = "Windows" } = params;

switch (action) {
case "add":
add();
break;
case "remove":
remove();
break;
case "cut":
cut();
break;
case "copy":
copy();
break;
case "paste":
paste();
break;
case "duplicate":
duplicate();
break;
case "move":
move();
break;
case "rename":
rename();
break;
default:
break;
}
) => {
try {
const {
projectContext,
action,
uids,
fileTree,
fileHandlers,
osType = "Windows",
} = params;

resolve();
} catch (err) {
LogAllow && console.error(err);
fb && fb();
reject();
let allDone = true;
switch (action) {
case "create":
create();
break;
case "remove":
allDone = await remove({
projectContext,
uids,
fileTree,
fileHandlers,
});
break;
case "cut":
cut();
break;
case "copy":
copy();
break;
case "duplicate":
duplicate();
break;
case "move":
move();
break;
case "rename":
rename();
break;
default:
break;
}
});

cb && cb(allDone);
} catch (err) {
LogAllow && console.error(err);
fb && fb();
}
};
Loading

0 comments on commit d134d40

Please sign in to comment.