bigbuffet-rw/packages/pl-hooks/lib/hooks/markers/use-update-marker-mutation.ts
marcin mikołajczak 9fef1d1f4e pl-hooks: Prefer kebab case for file names
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-10-23 15:27:02 +02:00

27 lines
853 B
TypeScript

import { useMutation } from '@tanstack/react-query';
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
import type { Timeline } from './use-markers';
import type { Marker } from 'pl-api';
const useUpdateMarkerMutation = (timeline: Timeline) => {
const { client } = usePlHooksApiClient();
const queryClient = usePlHooksQueryClient();
return useMutation({
mutationFn: (lastReadId: string) => client.timelines.saveMarkers({
[timeline]: {
last_read_id: lastReadId,
},
}),
retry: false,
onMutate: (lastReadId) => queryClient.setQueryData<Marker>(['markers', timeline], (marker) => marker ? ({
...marker,
last_read_id: lastReadId,
}) : undefined),
}, queryClient);
};
export { useUpdateMarkerMutation };