bigbuffet-rw/packages/pl-hooks/lib/hooks/markers/useMarkers.ts
marcin mikołajczak 9aa8ded6c6 Make pl-hooks self-containted
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-10-17 21:08:50 +02:00

26 lines
909 B
TypeScript

import { useQuery } from '@tanstack/react-query';
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
import { queryClient, usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
import type { PlApiClient } from 'pl-api';
type Timeline = 'home' | 'notifications';
const useMarker = (timeline: Timeline) => {
const queryClient = usePlHooksQueryClient();
const { client } = usePlHooksApiClient();
return useQuery({
queryKey: ['markers', timeline],
queryFn: () => client.timelines.getMarkers([timeline]).then(markers => markers[timeline]),
}, queryClient);
};
const prefetchMarker = (client: PlApiClient, timeline: 'home' | 'notifications') =>
queryClient.prefetchQuery({
queryKey: ['markers', timeline],
queryFn: () => client.timelines.getMarkers([timeline]).then(markers => markers[timeline]),
});
export { useMarker, prefetchMarker, type Timeline };