From bb717888112701794b9d47885ae07c851b8a932e Mon Sep 17 00:00:00 2001 From: billchen Date: Fri, 8 Mar 2024 19:23:15 +0800 Subject: [PATCH] feat: bind length of conversationList to chat count --- web/src/hooks/userSettingHook.ts | 2 +- web/src/pages/chat/chat-container/index.tsx | 16 ++++----- web/src/pages/chat/hooks.ts | 38 ++++++++++++--------- web/src/pages/chat/index.tsx | 2 +- web/src/pages/chat/model.ts | 18 ++-------- 5 files changed, 33 insertions(+), 43 deletions(-) diff --git a/web/src/hooks/userSettingHook.ts b/web/src/hooks/userSettingHook.ts index 0c13bebdda..7425dfd8b1 100644 --- a/web/src/hooks/userSettingHook.ts +++ b/web/src/hooks/userSettingHook.ts @@ -66,7 +66,7 @@ export const useSelectParserList = (): Array<{ }; export const useLogout = () => { - const dispatch = useDispatch(); + const dispatch = useDispatch(); // TODO: clear redux state const logout = useCallback((): number => { return dispatch({ type: 'loginModel/logout' }); diff --git a/web/src/pages/chat/chat-container/index.tsx b/web/src/pages/chat/chat-container/index.tsx index 3201b08a15..34bb6ddf94 100644 --- a/web/src/pages/chat/chat-container/index.tsx +++ b/web/src/pages/chat/chat-container/index.tsx @@ -162,15 +162,13 @@ const MessageItem = ({ })} > {item.role === MessageType.User ? ( - userInfo.avatar ?? ( - - ) + ) : ( )} diff --git a/web/src/pages/chat/hooks.ts b/web/src/pages/chat/hooks.ts index 23bff64694..47a3721f80 100644 --- a/web/src/pages/chat/hooks.ts +++ b/web/src/pages/chat/hooks.ts @@ -264,22 +264,26 @@ export const useSelectConversationList = () => { const prologue = currentDialog?.prompt_config?.prologue ?? ''; const addTemporaryConversation = useCallback(() => { - setList(() => { - const nextList = [ - { - id: '', - name: 'New conversation', - dialog_id: dialogId, - message: [ - { - content: prologue, - role: MessageType.Assistant, - }, - ], - } as IConversation, - ...conversationList, - ]; - return nextList; + setList((pre) => { + if (dialogId) { + const nextList = [ + { + id: '', + name: 'New conversation', + dialog_id: dialogId, + message: [ + { + content: prologue, + role: MessageType.Assistant, + }, + ], + } as IConversation, + ...conversationList, + ]; + return nextList; + } + + return pre; }); }, [conversationList, dialogId, prologue]); @@ -368,7 +372,7 @@ export const useSelectCurrentConversation = () => { }, []); const addPrologue = useCallback(() => { - if (conversationId === '') { + if (dialogId !== '' && conversationId === '') { const prologue = dialog.prompt_config?.prologue; const nextMessage = { diff --git a/web/src/pages/chat/index.tsx b/web/src/pages/chat/index.tsx index 961ce1a7a7..680cd77732 100644 --- a/web/src/pages/chat/index.tsx +++ b/web/src/pages/chat/index.tsx @@ -239,7 +239,7 @@ const Chat = () => { > Chat - 25 + {conversationList.length} diff --git a/web/src/pages/chat/model.ts b/web/src/pages/chat/model.ts index b3d632ba8d..f8950b34d1 100644 --- a/web/src/pages/chat/model.ts +++ b/web/src/pages/chat/model.ts @@ -59,20 +59,6 @@ const model: DvaModel = { currentConversation: { ...payload, message: messageList }, }; }, - addEmptyConversationToList(state, {}) { - const list = [...state.conversationList]; - // if (list.every((x) => x.id !== 'empty')) { - // list.push({ - // id: 'empty', - // name: 'New conversation', - // message: [], - // }); - // } - return { - ...state, - conversationList: list, - }; - }, }, effects: { @@ -100,7 +86,9 @@ const model: DvaModel = { }, *listDialog({ payload }, { call, put }) { const { data } = yield call(chatService.listDialog, payload); - yield put({ type: 'setDialogList', payload: data.data }); + if (data.retcode === 0) { + yield put({ type: 'setDialogList', payload: data.data }); + } }, *listConversation({ payload }, { call, put }) { const { data } = yield call(chatService.listConversation, payload);