From b78d1f89929098761e98a11688794bedc2a721cb Mon Sep 17 00:00:00 2001 From: upsiflu Date: Thu, 6 Feb 2025 18:56:10 +0100 Subject: [PATCH] refactor(front): [WIP] modernize upload form (for Channels) --- front/src/components/channels/UploadForm.vue | 332 +++++++++---------- 1 file changed, 163 insertions(+), 169 deletions(-) diff --git a/front/src/components/channels/UploadForm.vue b/front/src/components/channels/UploadForm.vue index 50e549d95..cac72b756 100644 --- a/front/src/components/channels/UploadForm.vue +++ b/front/src/components/channels/UploadForm.vue @@ -3,15 +3,13 @@ import type { BackendError, Channel, Upload, Track } from '~/types' import type { VueUploadItem } from 'vue-upload-component' import { computed, ref, reactive, watchEffect, watch } from 'vue' -import { whenever, useCurrentElement } from '@vueuse/core' +import { whenever } from '@vueuse/core' import { humanSize } from '~/utils/filters' import { useI18n } from 'vue-i18n' import { useStore } from '~/store' import axios from 'axios' -import $ from 'jquery' - import UploadMetadataForm from '~/components/channels/UploadMetadataForm.vue' import FileUploadWidget from '~/components/library/FileUploadWidget.vue' import LicenseSelect from '~/components/channels/LicenseSelect.vue' @@ -21,7 +19,6 @@ import useErrorHandler from '~/composables/useErrorHandler' interface Events { (e: 'status', status: UploadStatus): void - (e: 'step', step: 1 | 2 | 3): void } interface Props { @@ -238,7 +235,7 @@ const fetchAudioMetadata = async (uuid: string) => { for (const key of ['title', 'position', 'tags'] as const) { if (uploadImportData[uuid][key] === undefined) { - uploadImportData[uuid][key] = response.data[key] as never + // uploadImportData[uuid][key] = response.data[key] as never } } @@ -302,27 +299,7 @@ const retry = async (file: VueUploadItem) => { fetchChannels() fetchQuota() -// -// Step -// -const step = ref<1 | 2 | 3>(1) -watchEffect(() => { - emit('step', step.value) - - if (step.value === 2) { - selectedUploadId.value = null - } -}) - -watch(selectedUploadId, async (to, from) => { - if (to) { - step.value = 3 - } - - if (!to && step.value !== 2) { - step.value = 2 - } - +watch(selectedUploadId, async (_, from) => { if (from) { await patchUpload(from, { import_metadata: uploadImportData[from] }) } @@ -360,29 +337,42 @@ const labels = computed(() => ({ const isLoading = ref(false) const publish = async () => { + console.log("starting publish...") isLoading.value = true errors.value = [] try { - await axios.post('uploads/action/', { + // Post list of uuids of uploadedFiles to axios action:publish + await axios.put('uploads/action/', { action: 'publish', objects: uploadedFiles.value.map((file) => file.response?.uuid) }) + console.log("starting posting to axios action:publish...") + + console.log("Channels Store Before: ", store.state.channels) + + // Tell the store that the uploaded files are pending import store.commit('channels/publish', { uploads: uploadedFiles.value.map((file) => ({ ...file.response, import_status: 'pending' })), channel: selectedChannel.value }) + + console.log("Channels Store After: ", store.state.channels) + } catch (error) { + // TODO: Use inferred error type instead of typecasting errors.value = (error as BackendError).backendErrors + console.log("Error:", error) } isLoading.value = false + + console.log("...finished publish") } defineExpose({ - step, publish }) @@ -392,6 +382,8 @@ defineExpose({ :class="['ui', { loading: availableChannels.loading }, 'form component-file-upload']" @submit.stop.prevent > + +
-
+ + + +
@@ -417,13 +412,13 @@ defineExpose({ -
+

@@ -431,152 +426,151 @@ defineExpose({

-