diff --git a/src/lib/components/FilePanel.svelte b/src/lib/components/FilePanel.svelte index b4dc038..3b7e486 100644 --- a/src/lib/components/FilePanel.svelte +++ b/src/lib/components/FilePanel.svelte @@ -18,6 +18,7 @@ import { Trash, Pencil } from 'lucide-svelte'; import { Loader2, Check, X } from 'lucide-svelte'; + import StatusSpinner from './StatusSpinner.svelte'; let isLoading = false; let isUploaded = false; let isError = false; @@ -116,6 +117,10 @@ dispatcher('onUpload'); } + let deleting = false; + let delMessage = null; + let success = -1; + async function deleteRecording(event) { const delId = event.currentTarget.id; @@ -125,6 +130,8 @@ } try { + delMessage = `Deleting record ${delId}`; + deleting = true; // Delete the template const deleteResponse = await fetch(`/api/records?id=${delId}`, { method: 'DELETE' @@ -133,15 +140,26 @@ if (deleteResponse.ok) { const deleteResult = await deleteResponse.json(); console.log('Record deleted successfully:', deleteResult); + delMessage = 'Deleted'; + success = 1; // dispatch('templatesModified'); dispatcher('recordsModified'); } else { const error = await deleteResponse.json(); console.error('Error deleting record:', error); + delMessage = `Delete failed`; + success = 0; } } catch (err) { console.error('Error during API call:', err); + delMessage = `Delete failed`; + success = 0; + } finally { + setInterval(() => { + deleting = false; + success = -1; + }, 3000); } } @@ -252,8 +270,13 @@
+ {#if deleting} +
+ +
+ {/if}
diff --git a/src/lib/components/StatusSpinner.svelte b/src/lib/components/StatusSpinner.svelte index cead4af..47ccd89 100644 --- a/src/lib/components/StatusSpinner.svelte +++ b/src/lib/components/StatusSpinner.svelte @@ -1,9 +1,17 @@ -
- +
+
{msg}
+ {#if success < 0} + + {:else if success > 0} + + {:else} + + {/if}
diff --git a/src/lib/components/TemplatesPane.svelte b/src/lib/components/TemplatesPane.svelte index 2413d8c..7006ddb 100644 --- a/src/lib/components/TemplatesPane.svelte +++ b/src/lib/components/TemplatesPane.svelte @@ -4,6 +4,7 @@ import { createEventDispatcher } from 'svelte'; import { ContextMenu } from 'bits-ui'; import { Plus, Trash } from 'lucide-svelte'; + import StatusSpinner from './StatusSpinner.svelte'; export let templates; let dispatch = createEventDispatcher(); @@ -26,15 +27,25 @@ } } + let deleting = false; + let delMessage = null; + let success = -1; + async function deleteTemplate(event) { - const delId = event.target.id; + const delId = event.currentTarget.id; if (!delId) { console.error('Template ID is missing'); return; } + if (delId === clickedId) { + dispatch('onTemplateClick', null); + } + try { + delMessage = `Deleting record ${delId}`; + deleting = true; // Delete the template const deleteResponse = await fetch(`/api/templates?id=${delId}`, { method: 'DELETE' @@ -43,19 +54,35 @@ if (deleteResponse.ok) { const deleteResult = await deleteResponse.json(); console.log('Template deleted successfully:', deleteResult); + delMessage = `Deleted`; + success = 1; dispatch('templatesModified'); } else { const error = await deleteResponse.json(); console.error('Error deleting template:', error); + delMessage = `Delete failed`; + success = 0; } } catch (err) { console.error('Error during API call:', err); + delMessage = `Delete failed`; + success = 0; + } finally { + setInterval(() => { + deleting = false; + success = -1; + }, 3000); } } - +{#if deleting} +
+ +
+{/if} +
- + -
Delete
+
Delete
diff --git a/src/lib/components/UploadPane.svelte b/src/lib/components/UploadPane.svelte index ddff662..6816eef 100644 --- a/src/lib/components/UploadPane.svelte +++ b/src/lib/components/UploadPane.svelte @@ -1,12 +1,14 @@
-
Drag and Drop audio
{#if uploading} - + {#if ctr < nfiles} + + +
+
+
+ Uploading {currFile} +
+ {:else if !error} + + {:else} +
+
Upload failed
+ +
+ {/if} {:else} +
Drag and Drop audio
+
Or click to select
{/if}
- - - -
Upload
- -
+
diff --git a/src/routes/api/templates/+server.ts b/src/routes/api/templates/+server.ts index b482520..ed50199 100644 --- a/src/routes/api/templates/+server.ts +++ b/src/routes/api/templates/+server.ts @@ -62,3 +62,35 @@ export const POST: RequestHandler = async ({ request, locals }) => { }); } }; + +export const DELETE: RequestHandler = async ({ url, locals }) => { + const pb = locals.pb; + await ensureCollectionExists(pb); + + try { + // Extract the 'id' query parameter from the request URL + const id = url.searchParams.get('id'); + + if (!id) { + return new Response(JSON.stringify({ error: 'Record ID is required' }), { + status: 400, + headers: { 'Content-Type': 'application/json' } + }); + } + + // Delete the record from the PocketBase collection 'templates' + await pb.collection('templates').delete(id); + + // Respond with a success message + return new Response(JSON.stringify({ message: 'Record deleted successfully' }), { + status: 200, + headers: { 'Content-Type': 'application/json' } + }); + } catch (err) { + console.log('API records | Error deleting record', err); + return new Response(JSON.stringify({ error: err.message }), { + status: 500, + headers: { 'Content-Type': 'application/json' } + }); + } +};