Skip to content

Commit

Permalink
Remove cyclical structure from Entry types
Browse files Browse the repository at this point in the history
  • Loading branch information
chetbae committed Jun 28, 2023
1 parent fec9a9d commit 0e34f67
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
24 changes: 21 additions & 3 deletions src/Dashboard/FileSystem/FileSystemManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import { IFolder, IEntry, fs_functions } from '.';
import { fetchUploadedDocuments } from '../Storage';
import { samples_names } from '../samples';

const FileSystemManager = () => {
// Manager is used for accessing local storage and tracking the position of current folder
const FileSystemManager = async () => {

const root = await getFileSystem();
let currentFolder: IFolder = root;

const getRoot = (): IFolder => root;

// Save filesystem into local storage
function setFileSystem(fs: IFolder): boolean {
try {
console.log(1);
console.log(fs);
const save_fs = fs_functions.createRoot(fs.name, fs.content);
console.log(2);
window.localStorage.setItem('neon-fs', JSON.stringify(save_fs));
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -78,12 +88,20 @@ const FileSystemManager = () => {
return root;
}

const root = getFileSystem();
function setCurrentFolder(folder: IFolder) {
currentFolder = folder;
}

function getCurrentFolder(): IFolder {
return currentFolder;
}

const FileSystemProps = {
root: root,
getRoot: getRoot,
setFileSystem: setFileSystem,
getFileSystem: getFileSystem,
setCurrentFolder: setCurrentFolder,
getCurrentFolder: getCurrentFolder
}

return FileSystemProps;
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { EntryType, IEntry, IFolder, IFile } from '.';

/*
* File System Functions that are used to create, move, and delete file system entries
* Does not depend on state
*/

const createEntry = (name: string, type: EntryType, content: IEntry[] | string): IEntry => {
return {
name,
type,
content,
parent: null,
};
}

Expand Down Expand Up @@ -39,8 +43,6 @@ const moveEntry = (entry: IEntry, parent: IFolder, newParent: IFolder): boolean

const AddEntry = (entry: IEntry, parent: IFolder): boolean => {
try {
const AssignedEntry = { ...entry, parent: parent };

// Check for duplicate name
const isDuplicate = parent.content.some((e) => e.name === entry.name);
if (isDuplicate) {
Expand All @@ -49,7 +51,7 @@ const AddEntry = (entry: IEntry, parent: IFolder): boolean => {
}

// Add entry to parent
parent.content.push(AssignedEntry);
parent.content.push(entry);
parent.content.sort((a, b) => a.type.localeCompare(b.type));
parent.content.sort((a, b) => a.name.localeCompare(b.name));
} catch (e) {
Expand Down Expand Up @@ -79,8 +81,6 @@ const RemoveEntry = (entry: IEntry, parent: IFolder): boolean => {
return true;
}



export const fs_functions = {
createRoot: createRoot,
createFolder: createFolder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface IEntry {
name: string;
type: EntryType;
content: IEntry[] | string;
parent: IEntry;
}

export interface IFolder extends IEntry {
Expand Down
19 changes: 19 additions & 0 deletions src/Dashboard/FileSystem/fs_searcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IFile, IFolder, IEntry, EntryType } from '.';

// function getAbsolutePath(entry: IEntry, root?: IFolder): string[] {
// const path = [entry.name];
// let parent = entry.parent;

// while (parent) {
// path.unshift(parent.name);
// parent = parent.parent;
// }
// return path;
// }

// function findEntry(name: string, root: IFolder): IEntry {
// return
// }

export const fs_searcher = {
}

0 comments on commit 0e34f67

Please sign in to comment.