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