2025-01-23 19:41:31 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
2025-01-28 23:23:03 +03:00
|
|
|
import { DataCallback } from '@/backend/apiTransport';
|
2025-01-23 19:41:31 +03:00
|
|
|
import { useUpdateTimestamp } from '@/backend/library/useUpdateTimestamp';
|
|
|
|
import { LibraryItemID } from '@/models/library';
|
|
|
|
import { IRSFormData } from '@/models/rsform';
|
|
|
|
|
|
|
|
import { IInlineSynthesisDTO, rsformsApi } from './api';
|
|
|
|
|
|
|
|
export const useInlineSynthesis = () => {
|
|
|
|
const client = useQueryClient();
|
|
|
|
const { updateTimestamp } = useUpdateTimestamp();
|
|
|
|
const mutation = useMutation({
|
|
|
|
mutationKey: [rsformsApi.baseKey, 'inline-synthesis'],
|
|
|
|
mutationFn: rsformsApi.inlineSynthesis,
|
|
|
|
onSuccess: data => {
|
2025-01-28 19:45:31 +03:00
|
|
|
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
2025-01-23 19:41:31 +03:00
|
|
|
updateTimestamp(data.id);
|
|
|
|
// TODO: invalidate OSS?
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
inlineSynthesis: (
|
|
|
|
data: {
|
|
|
|
itemID: LibraryItemID; //
|
|
|
|
data: IInlineSynthesisDTO;
|
|
|
|
},
|
|
|
|
onSuccess?: DataCallback<IRSFormData>
|
|
|
|
) => mutation.mutate(data, { onSuccess })
|
|
|
|
};
|
|
|
|
};
|