From 9bbff9a3fa27eb18cbc6d3e22f4110d446a3138d Mon Sep 17 00:00:00 2001
From: zleyyij <75810274+zleyyij@users.noreply.github.com>
Date: Mon, 22 Jul 2024 14:20:50 -0600
Subject: [PATCH] feat: frontend can delete files now
---
frontend/src/lib/cache.ts | 13 ++-
.../components/ConfirmationDialogue.svelte | 87 +++++++++++++++++++
frontend/src/lib/components/Editor.svelte | 4 +-
.../src/lib/components/FileNavigation.svelte | 72 +++++++++++++--
frontend/src/routes/+page.svelte | 2 +-
5 files changed, 169 insertions(+), 9 deletions(-)
create mode 100644 frontend/src/lib/components/ConfirmationDialogue.svelte
diff --git a/frontend/src/lib/cache.ts b/frontend/src/lib/cache.ts
index 634e6aa..2fe0ab1 100644
--- a/frontend/src/lib/cache.ts
+++ b/frontend/src/lib/cache.ts
@@ -45,7 +45,7 @@ class AssetCache {
* @param path The key to store the entry under
* @param value The entry
*/
- async set(path: string, value: CacheEntry) {
+ set(path: string, value: CacheEntry) {
// evict the least recently used item if necessary
if (this.values.size >= this.maxEntries) {
const keyToDelete = this.values.keys().next().value;
@@ -55,6 +55,17 @@ class AssetCache {
this.values.set(path, value);
}
+ /**
+ * Remove the specified item from cache.
+ *
+ * This operation is **not write-through**, so changes
+ * are not synced to the backend.
+ * @param path
+ */
+ delete(path: string) {
+ this.values.delete(path)
+ }
+
/**
* Completely empty the cache of all entries.
*/
diff --git a/frontend/src/lib/components/ConfirmationDialogue.svelte b/frontend/src/lib/components/ConfirmationDialogue.svelte
new file mode 100644
index 0000000..1e3bec5
--- /dev/null
+++ b/frontend/src/lib/components/ConfirmationDialogue.svelte
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte
index 6512852..4279cec 100644
--- a/frontend/src/lib/components/Editor.svelte
+++ b/frontend/src/lib/components/Editor.svelte
@@ -63,7 +63,9 @@
}
currentFile.subscribe(async (v) => {
- editorText = (await cache.get(v)) ?? '';
+ if (v !== '') {
+ editorText = (await cache.get(v)) ?? '';
+ }
});
const unsubscribe = currentFile.subscribe(async (file) => {
diff --git a/frontend/src/lib/components/FileNavigation.svelte b/frontend/src/lib/components/FileNavigation.svelte
index 49f9446..1fc84d8 100644
--- a/frontend/src/lib/components/FileNavigation.svelte
+++ b/frontend/src/lib/components/FileNavigation.svelte
@@ -4,6 +4,7 @@
import { currentFile } from '$lib/main';
import { cache } from '$lib/cache';
import { get } from 'svelte/store';
+ import ConfirmationDialogue from './ConfirmationDialogue.svelte';
interface INode {
name: string;
children: INode[];
@@ -13,12 +14,15 @@
export let children: INode[] = [];
export let indent = 1;
export let path = name;
+ export let siblings: INode[] | undefined = undefined;
+ let self: HTMLElement;
let selected = false;
let open = false;
let showOptionsMenu = false;
let optionsMenu: HTMLDivElement;
let showNewFileInput = false;
let newFileInput: HTMLInputElement;
+ let showDeleteFileDialogue = false;
const dispatch = createEventDispatcher();
@@ -51,9 +55,28 @@
newFileInput.setSelectionRange(0, 0);
newFileInput.focus();
}
-
-
+ async function deleteDocumentHandler() {
+ showOptionsMenu = false;
+ if (get(currentFile) === path) {
+ currentFile.set('');
+ }
+ if (siblings !== undefined) {
+ // siblings.filter((n) => n.name !== name);
+ const entryToRemove = siblings.findIndex(n => n.name === name);
+ console.log(siblings.splice(entryToRemove, 1));
+ }
+ // TODO: requisite backend work, eg create DELETE
+ // handler for documents.
+
+ // While a re-render would happen when the directory
+ // is closed and re-opened, I nuke the current element here
+ // because I don't know how else to make it happen immediately
+ self.remove();
+ console.log(`Document "${path}" would be deleted`);
+ }
+
+
-
{#if showNewFileInput}
{#if children.length > 0}
-