Files
ncd-fe/packages/pl-hooks/lib/hooks/markers/use-markers.ts
nicole mikołajczyk bbf0325146 pl-hooks: migrate from eslint
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2026-02-24 14:01:33 +01:00

30 lines
918 B
TypeScript

import { useQuery } from '@tanstack/react-query';
import { usePlHooksApiClient } from '@/contexts/api-client';
import { queryClient, usePlHooksQueryClient } from '@/contexts/query-client';
import type { PlApiClient } from 'pl-api';
type Timeline = 'home' | 'notifications';
const useMarker = (timeline: Timeline) => {
const { client } = usePlHooksApiClient();
const queryClient = usePlHooksQueryClient();
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 };