fix(front): make all available fields available for editform (rebased on develop)

This commit is contained in:
ArneBo 2025-02-20 15:02:40 +01:00
parent d936e330d6
commit af58e94e73
1 changed files with 31 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import type { Album, Track, Actor } from '~/types'
import type { Album, Artist, Content, Track, Actor } from '~/types'
import { i18n } from '~/init/locale'
@ -16,14 +16,25 @@ export interface EditableConfigField extends ConfigField {
id: EditObjectType
}
export type EditObject = (Partial<Album> | Partial<Track>) & { attributed_to: Actor }
export type EditObjectType = 'album' | 'track'
export type EditObject = (Partial<Artist> | Partial<Album> | Partial<Track>) & { attributed_to: Actor }
export type EditObjectType = 'artist' | 'album' | 'track'
type Configs = Record<EditObjectType, { fields: (EditableConfigField|ConfigField)[] }>
const getContentValueRepr = (val: Content) => val.text
// TODO: Get params from typescript type somehow?
export default (): Configs => {
const { t } = i18n.global
const description: ConfigField = {
id: 'description',
type: 'content',
required: true,
label: t('composables.moderation.useEditConfigs.description.label'),
getValue: (obj) => obj.description ?? { text: '', content_type: 'text/markdown' },
getValueRepr: getContentValueRepr
}
const cover: ConfigField = {
id: 'cover',
type: 'attachment',
@ -37,15 +48,25 @@ export default (): Configs => {
type: 'tags',
required: true,
label: t('composables.moderation.useEditConfigs.tags.label'),
getValue: (obj) => ({
current: obj.tags || [],
others: [],
custom: [],
}),
getValue: (obj) => { return obj.tags },
getValueRepr: (tags: string[]) => tags.slice().sort().join('\n')
}
return {
artist: {
fields: [
{
id: 'name',
type: 'text',
required: true,
label: t('composables.moderation.useEditConfigs.artist.name'),
getValue: (artist) => (artist as Artist).name
},
description,
cover,
tags
]
},
album: {
fields: [
{
@ -55,9 +76,9 @@ export default (): Configs => {
label: t('composables.moderation.useEditConfigs.album.title'),
getValue: (album) => (album as Album).title
},
description,
{
id: 'release_date',
// TODO: Change type to date and offer date select input in form
type: 'text',
required: false,
label: t('composables.moderation.useEditConfigs.album.releaseDate'),
@ -76,6 +97,7 @@ export default (): Configs => {
label: t('composables.moderation.useEditConfigs.track.title'),
getValue: (track) => (track as Track).title
},
description,
cover,
{
id: 'position',