Fix globals fetch to handle singleton collection shape

This commit is contained in:
2026-04-23 21:16:42 +04:00
parent c8ee8a3ec2
commit e89a8175e2
2 changed files with 11 additions and 10 deletions

View File

@@ -1,21 +1,13 @@
import { queryOptions } from '@tanstack/react-query'
import { directusList, directusOne } from './directus'
import { GLOBALS_ID } from './env'
import { directusList, directusOne, directusSingleton } from './directus'
import type { Category, Globals, Menu, MenuRaw, PageEntity, Vendor, VendorListItem } from './types'
export const globalsQuery = queryOptions({
queryKey: ['globals'],
queryFn: async (): Promise<Globals> => {
const item = await directusOne<Globals>('globals', { fields: ['*'] })
if (!item) throw new Error('globals not found')
return item
},
queryFn: () => directusSingleton<Globals>('globals', { fields: ['*'] }),
staleTime: 5 * 60_000,
})
// globals is a singleton; if the ID ever changes, we could filter explicitly.
export { GLOBALS_ID }
export const menusQuery = queryOptions({
queryKey: ['menus'],
queryFn: async (): Promise<Menu[]> => {