* @janhq/plugin-core module * refactor web to use exported services from module * refactor data-plugin to provide DAL & move model logics to model management plugin * model-management in TS * add ci auto package, increate version, and publish to npm repository * chore: storage operations * chore: hybrid data-plugin esm & cjs module * chore: PouchDB Driver * chore: documentation --------- Co-authored-by: Hien To <hien@jan.ai> Co-authored-by: Service Account <service@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 "@janhq/plugin-core";
|
|
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.GetConversations
|
|
);
|
|
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;
|