update vuex
This commit is contained in:
1 parent
f1d9fc3778
commit
9c69e96416
3 files changed
+69
-3
No files matched your search
@@ -14,12 +14,67 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import Navigator from '@/components/common/Navigator.vue';
|
import Navigator from '@/components/common/Navigator.vue';
|
||||||
import Sidebar from '@/components/chat/Sidebar.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({
|
export default defineComponent({
|
||||||
name: 'LayoutChat',
|
name: 'LayoutChat',
|
||||||
components: {
|
components: {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
Navigator
|
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>
|
</script>
|
||||||
|
|||||||
+7
-3
@@ -1,21 +1,25 @@
|
|||||||
import { IApplication } from '@/operators';
|
import { IApplication } from '@/operators';
|
||||||
import { Module } from 'vuex';
|
import { Module } from 'vuex';
|
||||||
import { IChatState } from './models';
|
import { IChatState, Status } from './models';
|
||||||
|
|
||||||
export const chat: Module<IChatState, any> = {
|
export const chat: Module<IChatState, any> = {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state(): IChatState {
|
state(): IChatState {
|
||||||
return {
|
return {
|
||||||
applications: undefined
|
applications: undefined,
|
||||||
|
applicationsStatus: undefined
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setApplications(state: IChatState, payload: IApplication[]): void {
|
setApplications(state: IChatState, payload: IApplication[]): void {
|
||||||
state.applications = payload;
|
state.applications = payload;
|
||||||
|
},
|
||||||
|
setApplicationsStatus(state: IChatState, payload: Status): void {
|
||||||
|
state.applicationsStatus = payload;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setApplications({ commit }: any, payload: IApplication[]) {
|
async setApplications({ commit }: any, payload: IApplication[]) {
|
||||||
commit('setApplications', payload);
|
commit('setApplications', payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { IApplication, IMidjourneyPreset, IUser } from '@/operators';
|
import { IApplication, IMidjourneyPreset, IUser } from '@/operators';
|
||||||
|
|
||||||
|
export enum Status {
|
||||||
|
Request = 'Request',
|
||||||
|
Success = 'Success',
|
||||||
|
Error = 'Error'
|
||||||
|
}
|
||||||
|
|
||||||
export interface IToken {
|
export interface IToken {
|
||||||
access?: string;
|
access?: string;
|
||||||
refresh?: string;
|
refresh?: string;
|
||||||
@@ -24,6 +30,7 @@ export interface IMidjourneyState {
|
|||||||
|
|
||||||
export interface IChatState {
|
export interface IChatState {
|
||||||
applications: IApplication[] | undefined;
|
applications: IApplication[] | undefined;
|
||||||
|
applicationsStatus: Status | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRootState {
|
export interface IRootState {
|
||||||
|
|||||||
Reference in new issue
Block a user