diff --git a/src/lib/components/ui/DocumentUpload.svelte b/src/lib/components/ui/DocumentUpload.svelte new file mode 100644 index 0000000..3c7dc39 --- /dev/null +++ b/src/lib/components/ui/DocumentUpload.svelte @@ -0,0 +1,101 @@ + + +
{ + return async ({ update, result }) => { + await update(); + if (result.type === 'success') { + selectedFile = null; + if (fileInput) fileInput.value = ''; + } + }; +}}> + + +
fileInput.click()} + ondragover={(e) => { e.preventDefault(); dragging = true; }} + ondragleave={() => { dragging = false; }} + ondrop={handleDrop} + > + + + {#if selectedFile} +
+ + + +

{selectedFile}

+

Click Upload below or select a different file

+
+ {:else} + + + + +

Select Files to Upload

+

or Drag and Drop, Copy and Paste Files

+ {/if} +
+ + {#if selectedFile} +
+ + + +
+ {/if} +
diff --git a/src/lib/components/ui/ImageUpload.svelte b/src/lib/components/ui/ImageUpload.svelte new file mode 100644 index 0000000..eed0418 --- /dev/null +++ b/src/lib/components/ui/ImageUpload.svelte @@ -0,0 +1,105 @@ + + + + +
{ + return async ({ update, result }) => { + await update(); + if (result.type === 'success') { + selectedFile = null; + if (fileInput) fileInput.value = ''; + } + }; +}}> + + +
fileInput.click()} + ondragover={(e) => { e.preventDefault(); dragging = true; }} + ondragleave={() => { dragging = false; }} + ondrop={handleDrop} + > + + + {#if selectedFile} +
+ + + +

{selectedFile}

+

Click Upload below or select a different file

+
+ {:else} + + + + +

Select Files to Upload

+

or Drag and Drop, Copy and Paste Files

+ {/if} +
+ + {#if selectedFile} +
+ + + +
+ {/if} +
diff --git a/src/routes/(app)/components/[id]/+page.svelte b/src/routes/(app)/components/[id]/+page.svelte index 95ef449..f8afa58 100644 --- a/src/routes/(app)/components/[id]/+page.svelte +++ b/src/routes/(app)/components/[id]/+page.svelte @@ -2,6 +2,8 @@ import { enhance } from '$app/forms'; import { COMPONENT_CONDITIONS } from '$lib/constants.js'; import { formatDate, timeAgo } from '$lib/utils/date.js'; + import ImageUpload from '$lib/components/ui/ImageUpload.svelte'; + import DocumentUpload from '$lib/components/ui/DocumentUpload.svelte'; let { data, form } = $props(); const c = $derived(data.component); @@ -88,30 +90,9 @@
-
-

Images

- -
+

Images

- {#if showUploadForm} -
- { - const file = (e.target as HTMLInputElement).files?.[0]; - if (file && file.size > 50 * 1024 * 1024) { - alert('File too large. Maximum size is 50MB.'); - (e.target as HTMLInputElement).value = ''; - } - }} - class="text-sm text-gray-600 dark:text-gray-400" /> - - -
- {/if} + {#if data.images.length === 0}

No images yet.

@@ -330,21 +311,9 @@
-
-

Documents

- -
- {#if showDocForm} -
- - - -
- {/if} +

Documents

+ + {#if data.documents.length === 0}

No documents.

{:else} diff --git a/src/routes/(app)/devices/[id]/+page.svelte b/src/routes/(app)/devices/[id]/+page.svelte index 7cae9e9..641bbf4 100644 --- a/src/routes/(app)/devices/[id]/+page.svelte +++ b/src/routes/(app)/devices/[id]/+page.svelte @@ -1,6 +1,8 @@