- Add searchMessages, toggleBookmark, getBookmarks, branchConversation, listBranches, exportConversation to chatApi - Create useChatSearch hook with debounced FTS, placeholderData, 30s staleTime - Create useChatBookmarks and useToggleBookmark with cache invalidation for bookmarks and search queries
33 lines
1,020 B
TypeScript
33 lines
1,020 B
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { chatApi } from "../api/chat";
|
|
|
|
export function useChatBookmarks(companyId: string | null, conversationId?: string) {
|
|
const query = useQuery({
|
|
queryKey: ["chat", "bookmarks", companyId, conversationId],
|
|
queryFn: () => chatApi.getBookmarks(companyId!, conversationId),
|
|
enabled: !!companyId,
|
|
});
|
|
|
|
return {
|
|
data: query.data,
|
|
isLoading: query.isLoading,
|
|
};
|
|
}
|
|
|
|
export function useToggleBookmark() {
|
|
const queryClient = useQueryClient();
|
|
|
|
const mutation = useMutation({
|
|
mutationFn: ({ conversationId, messageId }: { conversationId: string; messageId: string }) =>
|
|
chatApi.toggleBookmark(conversationId, messageId),
|
|
onSuccess: () => {
|
|
void queryClient.invalidateQueries({ queryKey: ["chat", "bookmarks"] });
|
|
void queryClient.invalidateQueries({ queryKey: ["chat", "search"] });
|
|
},
|
|
});
|
|
|
|
return {
|
|
toggleBookmark: mutation.mutate,
|
|
isPending: mutation.isPending,
|
|
};
|
|
}
|