feat(front): add data models for the Search modal fix

2490-experiment-use-rstore
Flupsi 2025-08-14 14:41:05 +02:00
rodzic 6ae89f5c4f
commit 0728f01cd8
1 zmienionych plików z 8 dodań i 4 usunięć

Wyświetl plik

@ -5,9 +5,9 @@ import type { Split } from 'type-fest'
import type { components } from '~/generated/types'
import type { paths } from '~/generated/types'
/** @returns the most unique identifier per item, assuming every item has at least one key field */
export const getKey = (item: { fid: string } | { artist: { fid: string } }) =>
'fid' in item ? item.fid : item.artist.fid
/** @returns the most unique identifier available per item, assuming every item has at least one key field */
export const getKey = (item: { fid: string } | { artist: { fid: string } } | { id: number } | { name: string }) =>
'fid' in item ? item.fid : 'artist' in item ? item.artist.fid : 'id' in item ? item.id.toString() : item.name
/** Models
@ -17,7 +17,11 @@ TODO: Describe relations (perhaps wait for OpenAPI plugin)
*/
export const models = [
defineItemType<components['schemas']['Album']>().model({ name: 'albums', getKey }),
defineItemType<components['schemas']['Channel']>().model({ name: 'channels', getKey })
defineItemType<components['schemas']['Channel']>().model({ name: 'channels', getKey }),
defineItemType<components['schemas']['Track']>().model({ name: 'tracks', getKey }),
defineItemType<components['schemas']['Playlist']>().model({ name: 'playlists', getKey }),
defineItemType<components['schemas']['Radio']>().model({ name: 'radios', getKey }),
defineItemType<components['schemas']['Tag']>().model({ name: 'tags', getKey }),
] as const satisfies
ModelList satisfies
// Assert that the name is always the third segment in the API path: