mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-18 23:11:12 +02:00
replace imperative fetch in the reseacher page
This commit is contained in:
parent
db58571751
commit
7560ea1426
4 changed files with 44 additions and 83 deletions
|
|
@ -52,35 +52,6 @@ interface UseChatAPIProps {
|
|||
}
|
||||
|
||||
export function useChatAPI({ token, search_space_id }: UseChatAPIProps) {
|
||||
const fetchChatDetails = useCallback(
|
||||
async (chatId: string): Promise<ChatDetails | null> => {
|
||||
if (!token) return null;
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats/${Number(chatId)}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch chat details: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (err) {
|
||||
console.error("Error fetching chat details:", err);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
[token]
|
||||
);
|
||||
|
||||
const createChat = useCallback(
|
||||
async (
|
||||
initialMessage: string,
|
||||
|
|
@ -174,7 +145,6 @@ export function useChatAPI({ token, search_space_id }: UseChatAPIProps) {
|
|||
);
|
||||
|
||||
return {
|
||||
fetchChatDetails,
|
||||
createChat,
|
||||
updateChat,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue