* add empty conversation model selection Signed-off-by: James <james@jan.ai> * chore: using secondary button instead of sidebar button Signed-off-by: James <james@jan.ai> --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { Conversation, ConversationState } from "@/_models/Conversation";
|
|
import { useSetAtom } from "jotai";
|
|
import { executeSerial } from "@/_services/pluginService";
|
|
import { DataService } from "../../shared/coreService";
|
|
import {
|
|
conversationStatesAtom,
|
|
userConversationsAtom,
|
|
} from "@/_helpers/atoms/Conversation.atom";
|
|
|
|
const useGetUserConversations = () => {
|
|
const setConversationStates = useSetAtom(conversationStatesAtom);
|
|
const setConversations = useSetAtom(userConversationsAtom);
|
|
|
|
const getUserConversations = async () => {
|
|
try {
|
|
const convos: Conversation[] | undefined = await executeSerial(
|
|
DataService.GET_CONVERSATIONS
|
|
);
|
|
const convoStates: Record<string, ConversationState> = {};
|
|
convos?.forEach((convo) => {
|
|
convoStates[convo.id ?? ""] = {
|
|
hasMore: true,
|
|
waitingForResponse: false,
|
|
};
|
|
});
|
|
setConversationStates(convoStates);
|
|
setConversations(convos ?? []);
|
|
} catch (ex) {
|
|
console.log(ex);
|
|
}
|
|
};
|
|
|
|
return {
|
|
getUserConversations,
|
|
};
|
|
};
|
|
|
|
export default useGetUserConversations;
|