feat: Implement mobile application and lead processing utilities.
This commit is contained in:
@@ -1,22 +1,28 @@
|
||||
import { trpc } from '@/lib/trpc'
|
||||
import { useState } from 'react'
|
||||
import { MOCK_NEWS } from '@/lib/mock-data'
|
||||
import { useNewsReadStore } from '@/store/news.store'
|
||||
|
||||
export function useNewsList(kategorie?: string) {
|
||||
return trpc.news.list.useQuery({
|
||||
kategorie: kategorie as never,
|
||||
})
|
||||
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 markReadMutation = trpc.news.markRead.useMutation()
|
||||
|
||||
const query = trpc.news.byId.useQuery({ id })
|
||||
const news = MOCK_NEWS.find((n) => n.id === id) ?? null
|
||||
|
||||
function onOpen() {
|
||||
markRead(id)
|
||||
markReadMutation.mutate({ newsId: id })
|
||||
}
|
||||
|
||||
return { ...query, onOpen }
|
||||
return { data: news, isLoading: false, onOpen }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user