funkwhale/front/src/components/channels/UploadMetadataForm.vue

98 wiersze
2.3 KiB
Vue
Czysty Zwykły widok Historia

2022-07-30 19:56:44 +00:00
<script setup lang="ts">
import type { Upload, Track } from '~/types'
2022-07-30 19:56:44 +00:00
2025-04-14 12:11:49 +00:00
import { reactive, computed, watch, ref } from 'vue'
import { useI18n } from 'vue-i18n'
2022-07-30 19:56:44 +00:00
import AttachmentInput from '~/components/common/AttachmentInput.vue'
2025-04-14 12:11:49 +00:00
import Input from '~/components/ui/Input.vue'
import Pills from '~/components/ui/Pills.vue'
type Values = Pick<Track, 'title' | 'position' | 'tags'> & { cover: string | null, description: string }
2022-08-30 20:23:17 +00:00
interface Events {
2022-08-31 16:39:24 +00:00
(e: 'update:values', values: Values): void
2022-07-30 19:56:44 +00:00
}
interface Props {
upload: Upload
values: Partial<Values> | null
2022-07-30 19:56:44 +00:00
}
const { t } = useI18n()
2022-08-30 20:23:17 +00:00
const emit = defineEmits<Events>()
2022-07-30 19:56:44 +00:00
const props = withDefaults(defineProps<Props>(), {
values: null
})
2025-04-14 12:11:49 +00:00
// TODO: Make Tags work
type Item = { type: 'custom' | 'preset', label: string }
type tagsModel = {
currents: Item[],
others?: Item[],
}
2025-04-14 12:37:14 +00:00
const tags = ref<tagsModel>({
2025-04-14 12:11:49 +00:00
currents: [],
others: []
2025-04-14 12:37:14 +00:00
})
2025-04-14 12:11:49 +00:00
// TODO: check if `position: 0` is a good default
const newValues = reactive<Values>({
position: 0,
description: '',
title: '',
2025-04-14 12:11:49 +00:00
tags: tags.value.currents.map(tag => tag.label),
cover: null,
...(props.values ?? props.upload.import_metadata ?? {})
2022-08-31 16:39:24 +00:00
})
2022-07-30 19:56:44 +00:00
const isLoading = computed(() => !props.upload)
watch(newValues, (values) => emit('update:values', values), { immediate: true })
2022-07-30 19:56:44 +00:00
</script>
<template>
2025-04-14 12:11:49 +00:00
<Layout
form
:class="[{loading: isLoading}]"
>
<Input
v-model="newValues.title"
:label="t('components.channels.UploadMetadataForm.label.title')"
required
/>
<attachment-input
v-model="newValues.cover"
2022-08-31 16:39:24 +00:00
@delete="newValues.cover = ''"
2021-12-06 10:35:20 +00:00
>
{{ t('components.channels.UploadMetadataForm.label.image') }}
</attachment-input>
2025-04-14 12:11:49 +00:00
<label for="upload-tags">
{{ t('components.channels.UploadMetadataForm.label.tags') }}
</label>
<!-- TODO: Make Tags work -->
<Pills
:get="(v) => { tags = v }"
:set="() => tags"
label="Custom Tags"
cancel="Cancel"
/>
<Spacer />
<Input
v-model="newValues.position"
type="number"
min="1"
step="1"
:label="t('components.channels.UploadMetadataForm.label.position')"
/>
<label for="upload-description">
{{ t('components.channels.UploadMetadataForm.label.description') }}
</label>
<content-form
v-model="newValues.description"
field-id="upload-description"
/>
</Layout>
</template>