fix(front): channel create album modal
This commit is contained in:
parent
28a5e53850
commit
ab715611ab
|
@ -3,7 +3,7 @@ import type { Channel, BackendError } from '~/types'
|
||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
import { watch, ref } from 'vue'
|
import { watch, computed, ref } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useModal } from '~/ui/composables/useModal.ts'
|
import { useModal } from '~/ui/composables/useModal.ts'
|
||||||
|
|
||||||
|
@ -20,20 +20,14 @@ const emit = defineEmits(['created'])
|
||||||
const newAlbumTitle = ref<string>('')
|
const newAlbumTitle = ref<string>('')
|
||||||
|
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
const submittable = ref(false)
|
const submittable = computed(() => newAlbumTitle.value.length > 0)
|
||||||
const errors = ref<string[]>([])
|
const errors = ref<string[]>([])
|
||||||
|
|
||||||
const { isOpen: show } = useModal('album')
|
const isOpen = useModal('album').isOpen
|
||||||
|
|
||||||
watch(show, () => {
|
watch(isOpen, () => {
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
submittable.value = false
|
newAlbumTitle.value = '' // Reset the title to ensure submittable becomes false
|
||||||
})
|
|
||||||
|
|
||||||
// Create a new Album and tell the parent to re-fetch all albums
|
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
show
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
|
@ -43,29 +37,32 @@ const submit = async () => {
|
||||||
try {
|
try {
|
||||||
await axios.post('albums/', {
|
await axios.post('albums/', {
|
||||||
title: newAlbumTitle.value,
|
title: newAlbumTitle.value,
|
||||||
artist_credit: [channel.value.artist?.id]
|
artist: channel.value.artist?.id
|
||||||
})
|
})
|
||||||
|
emit('created')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errors.value = (error as BackendError).backendErrors
|
errors.value = (error as BackendError).backendErrors
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false
|
||||||
|
isOpen.value = false // TODO: Fix the @created event to close the modal in channels/DetailOverview.vue
|
||||||
}
|
}
|
||||||
|
|
||||||
emit('created')
|
|
||||||
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
submit
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Modal
|
<Modal
|
||||||
v-model="show"
|
v-model="isOpen"
|
||||||
:title="channel?.artist?.content_category === 'podcast' ? t('components.channels.AlbumModal.header.newSeries') : t('components.channels.AlbumModal.header.newAlbum')"
|
:title="channel?.artist?.content_category === 'podcast' ? t('components.channels.AlbumModal.header.newSeries') : t('components.channels.AlbumModal.header.newAlbum')"
|
||||||
class="small"
|
class="small"
|
||||||
:cancel="t('components.channels.AlbumModal.button.cancel')"
|
:cancel="t('components.channels.AlbumModal.button.cancel')"
|
||||||
>
|
>
|
||||||
<template #alert>
|
<template #alert>
|
||||||
<Alert
|
<Alert
|
||||||
v-if="errors.length > 0"
|
v-if="errors?.length > 0"
|
||||||
red
|
red
|
||||||
>
|
>
|
||||||
<h4 class="header">
|
<h4 class="header">
|
||||||
|
|
|
@ -94,8 +94,6 @@ if (isOwner.value) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const albumModal = ref()
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -207,7 +205,8 @@ const albumModal = ref()
|
||||||
<album-modal
|
<album-modal
|
||||||
v-if="isOwner"
|
v-if="isOwner"
|
||||||
:model-value="object"
|
:model-value="object"
|
||||||
@created="albumModal.show = false; seriesKey = new Date()"
|
:channel="object"
|
||||||
|
@created="useModal('album').isOpen.value = false; seriesKey = new Date()"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue