feat(SPA): media field type

This commit is contained in:
Florian Sylvain committed 2026-10-21 15:17:15 +02:00
1 parent a2d596f4ca
commit 3e7fc9a4a5
57 files changed
+6109 -75

No files matched your search

+29 -1
View File
@@ -11,7 +11,7 @@ import { ApiError, NetworkError, useApi } from '@/composables/useApi'
import { useContentTypesStore } from '@/stores/contentTypes'
import { useSessionStore } from '@/stores/session'
import { DESKTOP_WIDTH, setViewportWidth } from '@/components/__tests__/viewport'
import { eventsFields, recipesFields } from '@/lib/__tests__/schemaFixtures'
import { apiField, eventsFields, recipesFields } from '@/lib/__tests__/schemaFixtures'
export { apiField, eventsFields, recipesFields } from '@/lib/__tests__/schemaFixtures'
@@ -44,6 +44,21 @@ export const customTypes = [
},
].map((type) => ({ ...type, created_at: '2026-09-01T09:30:00Z' }))
export function thumbnailField(rest: object = {}) {
return apiField('Thumbnail', 'thumbnail', 'media', { options: [], ...rest })
}
export function eventsWithThumbnail(rest: object = {}) {
return { ...customTypes[0]!, fields: [...eventsFields, thumbnailField(rest)] }
}
export function thumbnailMount(rest: object = {}) {
return {
content: () => [eventsWithThumbnail(rest), customTypes[1]!, customTypes[2]!],
type: (key: string) => (key === 'events' ? eventsWithThumbnail(rest) : customTypes[1]),
}
}
function articleField(label: string, key: string, type: string, rest: object = {}) {
return {
key,
@@ -122,6 +137,14 @@ export interface PostedRequest {
export const entryCounts: Record<string, number> = { events: 37, recipes: 0 }
export const emptyLibrary = {
items: [],
total: 0,
page: 1,
size: 25,
counts: { all: 0, unused: 0, duplicates: 0 },
}
export function entryPage(total: number) {
return { items: [], total, page: 1, size: 1 }
}
@@ -157,6 +180,7 @@ export interface SchemaMount {
type?: (key: string) => unknown
list?: (key: string, query: URLSearchParams) => unknown
lookup?: (ids: number[]) => unknown
library?: (query: URLSearchParams) => unknown
before?: () => void
}
@@ -226,6 +250,10 @@ export async function mountAt(path: string, options: SchemaMount = {}, shellOnly
return (options.create ?? (() => createdType(body)))(body)
}
calls.push(url)
const library = url.match(/^\/v1\/media\/\?(.*)$/)
if (library) {
return (options.library ?? (() => emptyLibrary))(new URLSearchParams(library[1]))
}
if (url === '/v1/content-type') {
return (options.content ?? (() => [...customTypes]))()
}