Skip to content

Commit

Permalink
create make folder function
Browse files Browse the repository at this point in the history
  • Loading branch information
chetbae committed Jul 6, 2023
1 parent 76faf99 commit 464ac3d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
10 changes: 10 additions & 0 deletions assets/img/new-folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions deployment/server/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

<div class="main-section-action-bar">
<img id="upload-new-doc-button" class="action-bar-item-container active" src="./Neon-gh/assets/img/new-doc.svg" title="upload">
<img id="add-folder-button" class="action-bar-item-container active" src="./Neon-gh/assets/img/new-folder.svg" title="folder">
<div class="dividing-line action-bar-item-container active"></div>
<img id="remove-doc" class="action-bar-item-container" src="./Neon-gh/assets/img/remove-doc.svg" title="delete">
<img id="open-doc" class="action-bar-item-container" src="./Neon-gh/assets/img/open-doc.svg" title="open">
Expand Down
31 changes: 25 additions & 6 deletions src/Dashboard/DocumentSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const navBackButton: HTMLButtonElement = document.querySelector('#fs-back-btn');
const navPathContainer: HTMLDivElement = document.querySelector('#nav-path-container');

const uploadDocumentsButton = document.querySelector('#upload-new-doc-button');
const newFolderButton = document.querySelector('#add-folder-button');

const shiftSelection = new ShiftSelectionManager();
const fsm = FileSystemManager();
Expand All @@ -27,9 +28,11 @@ let orderedSelection: boolean[];
let metaKeyIsPressed = false;
let shiftKeyIsPressed = false;

navBackButton!.addEventListener('click', handleNavigateBack);
openButton!.addEventListener('click', handleOpenDocuments);
deleteButton!.addEventListener('click', handleDeleteDocuments);
navBackButton!.addEventListener('click', handleNavigateBack);
uploadDocumentsButton!.addEventListener('click', () => InitUploadArea(currentPath.at(-1)));
newFolderButton!.addEventListener('click', handleCreateFolder)

window.addEventListener('keydown', (e) => {
if (e.metaKey) metaKeyIsPressed = true;
Expand Down Expand Up @@ -58,10 +61,6 @@ backgroundArea!.addEventListener('click', (e) => {
}
});

uploadDocumentsButton!.addEventListener('click', function() {
InitUploadArea(currentPath.at(-1));
});

// gets user selected filenames
function getSelectionFilenames() {
return orderedEntries.filter((_, idx) => orderedSelection[idx]);
Expand Down Expand Up @@ -216,6 +215,13 @@ function handleOpenDocuments() {
}

function handleDeleteDocuments() {
// abort if parent folder is immutable
const isImmutable = currentPath.at(-1).metadata['immutable'];
if (isImmutable) {
window.alert(`Cannot delete documents. ${currentPath.join('/')} is immutable.`);
return;
}

function deleteFileEntry(file: IFile): Promise<boolean> {
return new Promise((resolve, reject) => {
deleteEntry(file.content)
Expand Down Expand Up @@ -250,7 +256,7 @@ function handleDeleteDocuments() {
// Create a formatted list of filenames to display in alert message
const createList = (entryArray: IEntry[]) => entryArray.map(entry => `- ${entry.name} (${entry.type})`).join('\n');

let alertMessage: string;
let alertMessage = '';

if (immutableEntries.length > 0) {
const immutableMessage = `The following files cannot be deleted:\n${createList(immutableEntries)}\n`;
Expand Down Expand Up @@ -316,6 +322,19 @@ function updateNavPath(currentPath: IFolder[]): void {
});
}

function handleCreateFolder() {
// abort if parent folder is immutable
const isImmutable = currentPath.at(-1).metadata['immutable'];
if (isImmutable) {
window.alert(`Cannot add folder. ${currentPath.join('/')} is immutable.`);
return;
}

const folder = fs_functions.createFolder('new file');
fs_functions.addEntry(folder, currentPath.at(-1));
updateDocumentSelector();
}

export async function updateDocumentSelector(newPath?: IFolder[]): Promise<void> {
if (!newPath) newPath = currentPath;
currentPath = newPath;
Expand Down

0 comments on commit 464ac3d

Please sign in to comment.