fix
This commit is contained in:
1 parent
d206c7df38
commit
affd47193c
14 files changed
+73
-160
No files matched your search
+1
-59
@@ -1,9 +1,7 @@
|
||||
import { createStore, ActionContext } from 'vuex';
|
||||
import createPersistedState from 'vuex-persistedstate';
|
||||
import { userOperator, IUser } from '@/operators';
|
||||
import { removeCookies } from '@/utils/cookie';
|
||||
import { IConversation } from '@/operators/conversation/models';
|
||||
import { DEFAULT_API, ENDPOINT } from '@/constants';
|
||||
import { ENDPOINT } from '@/constants';
|
||||
|
||||
export interface ISetting {
|
||||
stream?: boolean;
|
||||
@@ -12,10 +10,6 @@ export interface ISetting {
|
||||
|
||||
export interface IState {
|
||||
accessToken: string | undefined;
|
||||
refreshToken: string | undefined;
|
||||
user: IUser | undefined;
|
||||
activeApiId: string | undefined;
|
||||
conversations: IConversation[];
|
||||
setting: ISetting;
|
||||
}
|
||||
|
||||
@@ -23,10 +17,6 @@ const store = createStore({
|
||||
state(): IState {
|
||||
return {
|
||||
accessToken: undefined,
|
||||
refreshToken: undefined,
|
||||
user: undefined,
|
||||
activeApiId: DEFAULT_API.id,
|
||||
conversations: [],
|
||||
setting: {
|
||||
endpoint: ENDPOINT,
|
||||
stream: false
|
||||
@@ -37,59 +27,23 @@ const store = createStore({
|
||||
setAccessToken(state: IState, payload: string): void {
|
||||
state.accessToken = payload;
|
||||
},
|
||||
setRefreshToken(state: IState, payload: string): void {
|
||||
state.refreshToken = payload;
|
||||
},
|
||||
setUser(state: IState, payload: IUser): void {
|
||||
state.user = payload;
|
||||
},
|
||||
setSetting(state: IState, payload: ISetting): void {
|
||||
state.setting = {
|
||||
...state.setting,
|
||||
...payload
|
||||
};
|
||||
},
|
||||
setConversations(state: IState, payload: IConversation[]): void {
|
||||
state.conversations = payload;
|
||||
},
|
||||
setActiveApiId(state: IState, payload: string): void {
|
||||
state.activeApiId = payload;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
resetAuth({ commit }) {
|
||||
commit('setRefreshToken', undefined);
|
||||
commit('setAccessToken', undefined);
|
||||
commit('setUser', undefined);
|
||||
removeCookies();
|
||||
},
|
||||
setRefreshToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setRefreshToken', payload);
|
||||
},
|
||||
setAccessToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setAccessToken', payload);
|
||||
},
|
||||
setUser({ commit }: ActionContext<IState, IState>, payload: IUser) {
|
||||
commit('setUser', payload);
|
||||
},
|
||||
setSetting({ commit }: ActionContext<IState, IState>, payload: ISetting) {
|
||||
commit('setSetting', payload);
|
||||
},
|
||||
setActiveApiId({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setActiveApiId', payload);
|
||||
},
|
||||
setConversations({ commit }: ActionContext<IState, IState>, payload: IConversation[]) {
|
||||
commit('setConversations', payload);
|
||||
},
|
||||
getMe({ commit }: ActionContext<IState, IState>) {
|
||||
userOperator
|
||||
.getMe()
|
||||
.then(({ data: data }) => {
|
||||
commit('setUser', data);
|
||||
})
|
||||
.catch(() => {
|
||||
console.error('failed to get user info');
|
||||
});
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
@@ -99,20 +53,8 @@ const store = createStore({
|
||||
accessToken(state): string | undefined {
|
||||
return state.accessToken;
|
||||
},
|
||||
activeApiId(state): string | undefined {
|
||||
return state.activeApiId;
|
||||
},
|
||||
refreshToken(state): string | undefined {
|
||||
return state.refreshToken;
|
||||
},
|
||||
user(state): IUser | undefined {
|
||||
return state.user;
|
||||
},
|
||||
setting(state): ISetting | undefined {
|
||||
return state.setting;
|
||||
},
|
||||
conversations(state): IConversation[] {
|
||||
return state.conversations || [];
|
||||
}
|
||||
},
|
||||
plugins: [createPersistedState()]
|
||||
|
||||
Reference in new issue
Block a user