diff --git a/src/components/Controlbar.tsx b/src/components/Controlbar.tsx index 0322b68..54de524 100644 --- a/src/components/Controlbar.tsx +++ b/src/components/Controlbar.tsx @@ -10,7 +10,7 @@ export default component$(() => { const loaded = useNanostore$(areFilesLoaded); const files = useNanostore$(dashboardFiles); const fileInputRef = useSignal(); - const uploadingFiles = useSignal | undefined>(); + const uploadingFile = useSignal | undefined>(); const now = useSignal(new Date()); useVisibleTask$(() => { @@ -20,22 +20,18 @@ export default component$(() => { return () => clearInterval(interval); }); - const uploadFiles = $(async () => { - if (!uploadingFiles.value) { - console.error("No file(s) selected for upload."); + const uploadFile = $(async () => { + if (!uploadingFile.value) { + console.error("No file selected for upload."); return; } try { - const ufiles = uploadingFiles.value as File[]; - - for (const file of ufiles) { - const name = file.name.replace(/[^a-zA-Z0-9_.-]/g, "_"); - const f = new File([file], name, { type: file.type }); - - await api.upload(f); - } + const unsafe = uploadingFile.value as File; + const name = unsafe.name.replace(/[^a-zA-Z0-9_.-]/g, "_"); + const f = new File([unsafe], name, { type: unsafe.type }); + await api.upload(f); files.value = await api.list(); } catch (error) { console.error("Error uploading file:", error); @@ -48,10 +44,9 @@ export default component$(() => { ref={fileInputRef} style="display: none;" onChange$={async (e: Event) => { - uploadingFiles.value = noSerialize(Object.values((e.target as HTMLInputElement).files || {})); - await uploadFiles(); + uploadingFile.value = noSerialize((e.target as HTMLInputElement).files![0]); + await uploadFile(); }} - multiple />
diff --git a/src/components/Dropzone.tsx b/src/components/Dropzone.tsx deleted file mode 100644 index 71e4698..0000000 --- a/src/components/Dropzone.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import { component$, useVisibleTask$ } from "@builder.io/qwik"; -import { useDropzone } from "~/hooks/dropzone"; -import { useNanostore$ } from "~/hooks/nanostores"; -import { api } from "~/lib/api"; -import { dashboardFiles } from "~/lib/stores"; -import { StereoFile } from "~/lib/types"; - -export default component$(() => { - const dashfiles = useNanostore$(dashboardFiles); - - const { - highlight, - onDragOver, - onDragLeave, - onInputChange, - triggerFileInput, - fileInputRef, - } = useDropzone(); - - useVisibleTask$(() => { - const dropzone = document.getElementById("dropzone"); - if (!dropzone) return; - const handler = async (e: DragEvent) => { - e.preventDefault(); - highlight.value = false; - const files = Array.from(e.dataTransfer?.files || []); - for (const file of files) { - const name = file.name.replace(/[^a-zA-Z0-9_.-]/g, "_"); - const f = new File([file], name, { type: file.type }); - await api.upload(f); - dashfiles.value = await api.list(); - } - }; - dropzone.addEventListener("drop", handler); - return () => dropzone.removeEventListener("drop", handler); - }); - - return ( -
-

drop file ehre

- -
- ); -}); \ No newline at end of file diff --git a/src/components/File.tsx b/src/components/File.tsx index 00158f4..3d82ba3 100644 --- a/src/components/File.tsx +++ b/src/components/File.tsx @@ -65,18 +65,14 @@ export default component$(({ file }: FileProps) => { return (
- + { (file.Name.endsWith(".png") || file.Name.endsWith(".jpg") || file.Name.endsWith(".jpeg")) && ( {file.Name} )} diff --git a/src/hooks/dropzone.tsx b/src/hooks/dropzone.tsx deleted file mode 100644 index e1817fe..0000000 --- a/src/hooks/dropzone.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { $, useSignal } from '@builder.io/qwik'; - -export const useDropzone = () => { - const highlight = useSignal(false); - - const onInputChange = $(async (e: Event) => { - e.preventDefault(); - }); - - const fileInputRef = useSignal(undefined); - - return { - highlight, - onDragOver: $((e: DragEvent) => { - e.preventDefault(); - highlight.value = true; - }), - onDragLeave: $((e: DragEvent) => { - e.preventDefault(); - highlight.value = false; - }), - onInputChange, - triggerFileInput: $(() => { - fileInputRef.value?.click(); - }), - fileInputRef, - }; -} \ No newline at end of file diff --git a/src/routes/dashboard/index.tsx b/src/routes/dashboard/index.tsx index d7f2567..4e9d6ea 100644 --- a/src/routes/dashboard/index.tsx +++ b/src/routes/dashboard/index.tsx @@ -1,7 +1,6 @@ import { component$, useVisibleTask$ } from "@builder.io/qwik"; import { routeLoader$, type DocumentHead } from "@builder.io/qwik-city"; import Controlbar from "~/components/Controlbar"; -// import Dropzone from "~/components/Dropzone"; import File from "~/components/File"; import { SolarUploadLinear, SvgSpinnersBarsRotateFade } from "~/components/Icons"; import { useNanostore$ } from "~/hooks/nanostores"; @@ -29,7 +28,6 @@ export default component$(() => { return ( <> - {/* */} {!loaded.value ? (
@@ -46,7 +44,7 @@ export default component$(() => {
) : ( -
+
{files.value.map((file) => ( ))}