feat: chat ui

This commit is contained in:
archer
2023-07-26 11:01:25 +08:00
parent 2b993b926a
commit 248be38939
19 changed files with 153 additions and 54 deletions

View File

@@ -4,12 +4,13 @@ import { immer } from 'zustand/middleware/immer';
import { ChatHistoryItemType } from '@/types/chat';
import type { InitChatResponse } from '@/api/response/chat';
import { delChatHistoryById, getChatHistory } from '@/api/chat';
import { delChatHistoryById, getChatHistory, clearChatHistoryByAppId } from '@/api/chat';
type State = {
history: ChatHistoryItemType[];
loadHistory: (data: { appId?: string }) => Promise<null>;
delHistory(history: string): Promise<void>;
clearHistory(appId: string): Promise<void>;
updateHistory: (history: ChatHistoryItemType) => void;
chatData: InitChatResponse;
setChatData: (e: InitChatResponse | ((e: InitChatResponse) => InitChatResponse)) => void;
@@ -69,6 +70,12 @@ export const useChatStore = create<State>()(
});
await delChatHistoryById(chatId);
},
async clearHistory(appId) {
set((state) => {
state.history = [];
});
await clearChatHistoryByAppId(appId);
},
updateHistory(history) {
const index = get().history.findIndex((item) => item.chatId === history.chatId);
set((state) => {

View File

@@ -29,7 +29,6 @@ export const clientInitData = async (): Promise<InitDateResponse> => {
beianText = res.systemEnv?.beianText;
googleClientVerKey = res.systemEnv?.googleClientVerKey;
baiduTongji = res.systemEnv?.baiduTongji;
console.log(res.feConfigs);
return res;
} catch (error) {

View File

@@ -19,7 +19,7 @@ type State = {
updateUserInfo: (user: UserUpdateParams) => void;
myApps: AppListItemType[];
myCollectionApps: AppListItemType[];
loadMyModels: () => Promise<null>;
loadMyApps: () => Promise<AppListItemType[]>;
appDetail: AppSchema;
loadAppDetail: (id: string, init?: boolean) => Promise<AppSchema>;
updateAppDetail(appId: string, data: AppUpdateParams): Promise<void>;
@@ -63,12 +63,12 @@ export const useUserStore = create<State>()(
},
myApps: [],
myCollectionApps: [],
async loadMyModels() {
async loadMyApps() {
const res = await getMyModels();
set((state) => {
state.myApps = res;
});
return null;
return res;
},
appDetail: defaultApp,
async loadAppDetail(id: string, init = false) {