From 9db564d0529781dac77e6a27d6c47cb726596031 Mon Sep 17 00:00:00 2001 From: ArneBo Date: Tue, 15 Apr 2025 12:59:19 +0200 Subject: [PATCH] fix(front): album select in upload form restored and working --- front/src/components/channels/AlbumSelect.vue | 76 ++++++++++++------- front/src/components/channels/UploadForm.vue | 22 ++---- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/front/src/components/channels/AlbumSelect.vue b/front/src/components/channels/AlbumSelect.vue index ab1fcf9ce..9134fa75c 100644 --- a/front/src/components/channels/AlbumSelect.vue +++ b/front/src/components/channels/AlbumSelect.vue @@ -2,44 +2,65 @@ import type { Album, Channel } from '~/types' import axios from 'axios' -import { ref, watch } from 'vue' +import { useVModel } from '@vueuse/core' +import { ref, watch, reactive } from 'vue' import { useI18n } from 'vue-i18n' import { useModal } from '~/ui/composables/useModal.ts' -import Layout from '~/components/ui/Layout.vue' +import AlbumModal from '~/components/channels/AlbumModal.vue' import Link from '~/components/ui/Link.vue' import Spacer from '~/components/ui/Spacer.vue' const { t } = useI18n() -const model = defineModel<{channel: Channel, albumId: Album['id'] | '', albums: Album[]}>({ required: true }) -const albums = ref([]) +interface Events { + (e: 'update:modelValue', value: string): void +} + +interface Props { + modelValue: string | null + channel: Channel | null +} + +const emit = defineEmits() +const props = withDefaults(defineProps(), { + modelValue: null, + channel: null +}) + +const value = useVModel(props, 'modelValue', emit) +const localChannel = ref(props.channel ?? { artist: {} } as Channel) + +watch(() => props.channel, (newChannel) => { + localChannel.value = newChannel ?? { artist: {} } as Channel +}) + +const albums = reactive([]) const isLoading = ref(false) +const fetchData = async () => { + albums.length = 0 + if (!props.channel?.artist) return -const fetchAlbums = async () => { isLoading.value = true const response = await axios.get('albums/', { params: { - artist: model.value.channel.artist?.id, + artist: props.channel?.artist.id, include_channels: 'true' } }) - albums.value = response.data.results + albums.push(...response.data.results) isLoading.value = false } -watch(() => model.value.channel, fetchAlbums, { immediate: true }) -watch(albums, (value) => { - if (value.length === 1) { model.value.albumId = albums.value[0].id } -}) +watch(() => props.channel, fetchData, { immediate: true }) diff --git a/front/src/components/channels/UploadForm.vue b/front/src/components/channels/UploadForm.vue index 74aa6b6b1..b90ee1e52 100644 --- a/front/src/components/channels/UploadForm.vue +++ b/front/src/components/channels/UploadForm.vue @@ -1,5 +1,5 @@