32 lines
744 B
TypeScript
32 lines
744 B
TypeScript
'use client'
|
|
import { useState, useEffect } from 'react'
|
|
|
|
export interface CmsItem {
|
|
id: string
|
|
collection: string
|
|
title: string | null
|
|
data: Record<string, unknown>
|
|
status: string
|
|
sortOrder: number
|
|
scheduledAt: string | null
|
|
expiresAt: string | null
|
|
publishedAt: string | null
|
|
}
|
|
|
|
export function useVulaContent(collection: string) {
|
|
const [items, setItems] = useState<CmsItem[]>([])
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
fetch(`/api/content/${collection}`)
|
|
.then(r => r.json())
|
|
.then((data: { items?: CmsItem[] }) => {
|
|
setItems(data.items ?? [])
|
|
setLoading(false)
|
|
})
|
|
.catch(() => setLoading(false))
|
|
}, [collection])
|
|
|
|
return { items, loading }
|
|
}
|