2024-10-04 15:13:47 -07:00
|
|
|
import { useMutation } from '@tanstack/react-query';
|
2024-10-12 15:15:58 -07:00
|
|
|
|
2024-10-17 12:08:50 -07:00
|
|
|
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
|
2024-10-22 06:28:57 -07:00
|
|
|
import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
2024-10-04 15:13:47 -07:00
|
|
|
|
|
|
|
import type { Timeline } from './useMarkers';
|
|
|
|
import type { Marker } from 'pl-api';
|
|
|
|
|
|
|
|
const useUpdateMarkerMutation = (timeline: Timeline) => {
|
2024-10-17 12:08:50 -07:00
|
|
|
const { client } = usePlHooksApiClient();
|
2024-10-22 06:28:57 -07:00
|
|
|
const queryClient = usePlHooksQueryClient();
|
2024-10-04 15:13:47 -07:00
|
|
|
|
|
|
|
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),
|
2024-10-22 06:28:57 -07:00
|
|
|
}, queryClient);
|
2024-10-04 15:13:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
export { useUpdateMarkerMutation };
|