23 lines
546 B
TypeScript
23 lines
546 B
TypeScript
import { trpc } from '@/lib/trpc'
|
|
import { useNewsReadStore } from '@/store/news.store'
|
|
|
|
export function useNewsList(kategorie?: string) {
|
|
return trpc.news.list.useQuery({
|
|
kategorie: kategorie as never,
|
|
})
|
|
}
|
|
|
|
export function useNewsDetail(id: string) {
|
|
const markRead = useNewsReadStore((s) => s.markRead)
|
|
const markReadMutation = trpc.news.markRead.useMutation()
|
|
|
|
const query = trpc.news.byId.useQuery({ id })
|
|
|
|
function onOpen() {
|
|
markRead(id)
|
|
markReadMutation.mutate({ newsId: id })
|
|
}
|
|
|
|
return { ...query, onOpen }
|
|
}
|