Skip to content

Commit

Permalink
feat: add delete option from row menu
Browse files Browse the repository at this point in the history
  • Loading branch information
n-peugnet committed Feb 21, 2022
1 parent 4a46bae commit d12c83d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
45 changes: 35 additions & 10 deletions src/view/FileList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
let newFolderModal = false;
let newFolder = "";
let deleteSelectedModal = false;
let deleteModal = false;
let renameModal = false;
let renameValue = "";
let renameInode: Inode;
let menuInode: Inode;
$: {
listFiles(path);
Expand Down Expand Up @@ -86,10 +87,13 @@
async function renameFile() {
renameModal = false;
await fs.moveFile(
renameInode.path,
parent(renameInode.path) + renameValue
);
await fs.moveFile(menuInode.path, parent(menuInode.path) + renameValue);
fileListUpdateIncr();
}
async function deleteFile() {
deleteModal = false;
await fs.deleteFile(menuInode.path);
fileListUpdateIncr();
}
Expand Down Expand Up @@ -196,11 +200,18 @@
</ToolbarContent>
</Toolbar>
<svelte:fragment slot="cell" let:cell let:row>
<FileListCell {fs} {cell} on:click-rename={() => {
renameInode = row.inode;
renameValue = renameInode.basename;
renameModal = true;
}} />
<FileListCell
{fs}
{cell}
on:click-menu={() => (menuInode = row.inode)}
on:click-rename={() => {
renameValue = menuInode.basename;
renameModal = true;
}}
on:click-delete={() => {
deleteModal = true;
}}
/>
</svelte:fragment>
</DataTable>
{:else}
Expand Down Expand Up @@ -246,6 +257,20 @@
<p>Are you sure you want to delete {checked.length} files?</p>
</Modal>

<Modal
bind:open={deleteModal}
size="xs"
danger
modalHeading="Delete this file"
primaryButtonText="Delete"
secondaryButtonText="Cancel"
shouldSubmitOnEnter={false}
on:click:button--secondary={() => (deleteModal = false)}
on:submit={deleteFile}
>
<p>Are you sure you want to delete the file <code>{menuInode?.basename}</code>?</p>
</Modal>

<ComposedModal size="sm" bind:open={renameModal} on:submit={renameFile}>
<ModalHeader title="Rename file" />
<ModalBody hasForm>
Expand Down
7 changes: 6 additions & 1 deletion src/view/FileListCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
</script>

{#if cell.key === "menu"}
<OverflowMenu flipped>
<OverflowMenu flipped on:click={() => dispatch("click-menu")}>
<OverflowMenuItem
text="Rename"
on:click={() => dispatch("click-rename")}
/>
<OverflowMenuItem
text="Delete"
danger
on:click={() => dispatch("click-delete")}
/>
</OverflowMenu>
{:else}
<div class="file-table-cell">
Expand Down

0 comments on commit d12c83d

Please sign in to comment.