Fix globals fetch to handle singleton collection shape
This commit is contained in:
@@ -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[]> => {
|
||||
|
||||
Reference in New Issue
Block a user