From 7f274e7780e563159bdff946de185d2376a91dff Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Fri, 1 Nov 2024 00:24:03 +0100 Subject: [PATCH] refactor: :recycle: Optimize file uploader --- components/composer/composer.vue | 20 +- components/composer/file-uploader.vue | 188 ------------------ .../composer/uploader/alt-text-editor.vue | 36 ++++ components/composer/uploader/file-preview.vue | 31 +++ .../composer/uploader/file-shadow-overlay.vue | 3 + components/composer/uploader/file-size.vue | 26 +++ .../composer/uploader/preview-content.vue | 32 +++ .../composer/uploader/remove-button.vue | 12 ++ components/composer/uploader/uploader.vue | 118 +++++++++++ 9 files changed, 263 insertions(+), 203 deletions(-) delete mode 100644 components/composer/file-uploader.vue create mode 100644 components/composer/uploader/alt-text-editor.vue create mode 100644 components/composer/uploader/file-preview.vue create mode 100644 components/composer/uploader/file-shadow-overlay.vue create mode 100644 components/composer/uploader/file-size.vue create mode 100644 components/composer/uploader/preview-content.vue create mode 100644 components/composer/uploader/remove-button.vue create mode 100644 components/composer/uploader/uploader.vue diff --git a/components/composer/composer.vue b/components/composer/composer.vue index 1dade8b..5583a2d 100644 --- a/components/composer/composer.vue +++ b/components/composer/composer.vue @@ -53,7 +53,7 @@ import RichTextboxInput from "../inputs/rich-textbox-input.vue"; import Note from "../social-elements/notes/note.vue"; import Button from "./button.vue"; // biome-ignore lint/style/useImportType: Biome doesn't see the Vue code -import FileUploader from "./file-uploader.vue"; +import FileUploader, { type FileData } from "./uploader/uploader.vue"; const uploader = ref | undefined>(undefined); const { Control_Enter, Command_Enter, Control_Alt } = useMagicKeys(); @@ -71,15 +71,7 @@ const openFilePicker = () => { uploader.value?.openFilePicker(); }; -const files = ref< - { - id: string; - file: File; - progress: number; - api_id?: string; - alt_text?: string; - }[] ->([]); +const files = ref([]); const handlePaste = (event: ClipboardEvent) => { if (event.clipboardData) { @@ -95,6 +87,7 @@ const handlePaste = (event: ClipboardEvent) => { id: nanoid(), file, progress: 0, + uploading: true, })), ); } @@ -109,11 +102,7 @@ watch( files, (newFiles) => { // If a file is uploading, set loading to true - if (newFiles.some((file) => file.progress < 1)) { - loading.value = true; - } else { - loading.value = false; - } + loading.value = newFiles.some((file) => file.uploading); }, { deep: true, @@ -143,6 +132,7 @@ onMounted(() => { id: nanoid(), file: new File([], file.url), progress: 1, + uploading: false, api_id: file.id, alt_text: file.description ?? undefined, })); diff --git a/components/composer/file-uploader.vue b/components/composer/file-uploader.vue deleted file mode 100644 index 1f427b9..0000000 --- a/components/composer/file-uploader.vue +++ /dev/null @@ -1,188 +0,0 @@ -