Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bind length of conversationList to chat count #116

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/src/hooks/userSettingHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>({ type: 'loginModel/logout' });
Expand Down
16 changes: 7 additions & 9 deletions web/src/pages/chat/chat-container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,13 @@ const MessageItem = ({
})}
>
{item.role === MessageType.User ? (
userInfo.avatar ?? (
<Avatar
size={40}
src={
userInfo.avatar ??
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
}
/>
)
<Avatar
size={40}
src={
userInfo.avatar ??
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
}
/>
) : (
<AssistantIcon></AssistantIcon>
)}
Expand Down
38 changes: 21 additions & 17 deletions web/src/pages/chat/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -368,7 +372,7 @@ export const useSelectCurrentConversation = () => {
}, []);

const addPrologue = useCallback(() => {
if (conversationId === '') {
if (dialogId !== '' && conversationId === '') {
const prologue = dialog.prompt_config?.prologue;

const nextMessage = {
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const Chat = () => {
>
<Space>
<b>Chat</b>
<Tag>25</Tag>
<Tag>{conversationList.length}</Tag>
</Space>
<Dropdown menu={{ items }}>
<FormOutlined />
Expand Down
18 changes: 3 additions & 15 deletions web/src/pages/chat/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ const model: DvaModel<ChatModelState> = {
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: {
Expand Down Expand Up @@ -100,7 +86,9 @@ const model: DvaModel<ChatModelState> = {
},
*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);
Expand Down