29 lines
779 B
TypeScript
29 lines
779 B
TypeScript
import { useState } from 'react'
|
|
import { MOCK_NEWS } from '@/lib/mock-data'
|
|
import { useNewsReadStore } from '@/store/news.store'
|
|
|
|
export function useNewsList(kategorie?: string) {
|
|
const localReadIds = useNewsReadStore((s) => s.readIds)
|
|
const filtered = kategorie
|
|
? MOCK_NEWS.filter((n) => n.kategorie === kategorie)
|
|
: MOCK_NEWS
|
|
|
|
const data = filtered.map((n) => ({
|
|
...n,
|
|
isRead: n.isRead || localReadIds.has(n.id),
|
|
}))
|
|
|
|
return { data, isLoading: false, refetch: () => {}, isRefetching: false }
|
|
}
|
|
|
|
export function useNewsDetail(id: string) {
|
|
const markRead = useNewsReadStore((s) => s.markRead)
|
|
const news = MOCK_NEWS.find((n) => n.id === id) ?? null
|
|
|
|
function onOpen() {
|
|
markRead(id)
|
|
}
|
|
|
|
return { data: news, isLoading: false, onOpen }
|
|
}
|