update vuex

This commit is contained in:
AceDataCloud committed 2023-12-30 12:17:13 +08:00
1 parent f1d9fc3778
commit 9c69e96416
3 files changed
+69 -3

No files matched your search

+55
View File
@@ -14,12 +14,67 @@
import { defineComponent } from 'vue';
import Navigator from '@/components/common/Navigator.vue';
import Sidebar from '@/components/chat/Sidebar.vue';
import {
CHAT_MODEL_CHATGPT,
CHAT_MODEL_CHATGPT4,
CHAT_MODEL_CHATGPT4_BROWSING,
CHAT_MODEL_CHATGPT_16K,
CHAT_MODEL_CHATGPT_BROWSING,
applicationOperator
} from '@/operators';
export default defineComponent({
name: 'LayoutChat',
components: {
Sidebar,
Navigator
},
data() {
return {
initializing: false,
applications: this.$store.state.chat.applications || undefined
};
},
mounted() {
this.onFetchApplications();
},
methods: {
async onFetchConversations() {
this.loading = true;
const {
data: { items: apiUsages }
} = await apiUsageOperator.getAll({
user_id: this.$store.state.common.user.id,
// @ts-ignore
application_id: this.applications?.map((application) => application.id),
offset: 0,
limit: 30,
ordering: '-created_at'
});
this.loading = false;
// de duplicate conversations using id
const conversationIds: string[] = apiUsages
.map((apiUsage) => apiUsage.metadata?.conversation_id)
.filter((id) => id);
const uniqueConversationIds = [...new Set(conversationIds)];
const conversations = (await chatOperator.getConversations(uniqueConversationIds)).data;
this.conversations = conversations;
},
async onFetchApplications() {
this.initializing = true;
const { data: applications } = await applicationOperator.getAll({
user_id: this.$store.state.common.user.id,
api_id: [
CHAT_MODEL_CHATGPT.apiId,
CHAT_MODEL_CHATGPT_16K.apiId,
CHAT_MODEL_CHATGPT_BROWSING.apiId,
CHAT_MODEL_CHATGPT4.apiId,
CHAT_MODEL_CHATGPT4_BROWSING.apiId
]
});
this.initializing = false;
this.$store.dispatch('chat/setApplications', applications?.items);
}
}
});
</script>
+7 -3
View File
@@ -1,21 +1,25 @@
import { IApplication } from '@/operators';
import { Module } from 'vuex';
import { IChatState } from './models';
import { IChatState, Status } from './models';
export const chat: Module<IChatState, any> = {
namespaced: true,
state(): IChatState {
return {
applications: undefined
applications: undefined,
applicationsStatus: undefined
};
},
mutations: {
setApplications(state: IChatState, payload: IApplication[]): void {
state.applications = payload;
},
setApplicationsStatus(state: IChatState, payload: Status): void {
state.applicationsStatus = payload;
}
},
actions: {
setApplications({ commit }: any, payload: IApplication[]) {
async setApplications({ commit }: any, payload: IApplication[]) {
commit('setApplications', payload);
}
}
+7
View File
@@ -1,5 +1,11 @@
import { IApplication, IMidjourneyPreset, IUser } from '@/operators';
export enum Status {
Request = 'Request',
Success = 'Success',
Error = 'Error'
}
export interface IToken {
access?: string;
refresh?: string;
@@ -24,6 +30,7 @@ export interface IMidjourneyState {
export interface IChatState {
applications: IApplication[] | undefined;
applicationsStatus: Status | undefined;
}
export interface IRootState {