balibabu commited on
Commit
ef0f1be
·
1 Parent(s): c127ae4

feat: bind length of conversationList to chat count (#116)

Browse files
web/src/hooks/userSettingHook.ts CHANGED
@@ -66,7 +66,7 @@ export const useSelectParserList = (): Array<{
66
  };
67
 
68
  export const useLogout = () => {
69
- const dispatch = useDispatch();
70
 
71
  const logout = useCallback((): number => {
72
  return dispatch<any>({ type: 'loginModel/logout' });
 
66
  };
67
 
68
  export const useLogout = () => {
69
+ const dispatch = useDispatch(); // TODO: clear redux state
70
 
71
  const logout = useCallback((): number => {
72
  return dispatch<any>({ type: 'loginModel/logout' });
web/src/pages/chat/chat-container/index.tsx CHANGED
@@ -162,15 +162,13 @@ const MessageItem = ({
162
  })}
163
  >
164
  {item.role === MessageType.User ? (
165
- userInfo.avatar ?? (
166
- <Avatar
167
- size={40}
168
- src={
169
- userInfo.avatar ??
170
- 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
171
- }
172
- />
173
- )
174
  ) : (
175
  <AssistantIcon></AssistantIcon>
176
  )}
 
162
  })}
163
  >
164
  {item.role === MessageType.User ? (
165
+ <Avatar
166
+ size={40}
167
+ src={
168
+ userInfo.avatar ??
169
+ 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
170
+ }
171
+ />
 
 
172
  ) : (
173
  <AssistantIcon></AssistantIcon>
174
  )}
web/src/pages/chat/hooks.ts CHANGED
@@ -264,22 +264,26 @@ export const useSelectConversationList = () => {
264
  const prologue = currentDialog?.prompt_config?.prologue ?? '';
265
 
266
  const addTemporaryConversation = useCallback(() => {
267
- setList(() => {
268
- const nextList = [
269
- {
270
- id: '',
271
- name: 'New conversation',
272
- dialog_id: dialogId,
273
- message: [
274
- {
275
- content: prologue,
276
- role: MessageType.Assistant,
277
- },
278
- ],
279
- } as IConversation,
280
- ...conversationList,
281
- ];
282
- return nextList;
 
 
 
 
283
  });
284
  }, [conversationList, dialogId, prologue]);
285
 
@@ -368,7 +372,7 @@ export const useSelectCurrentConversation = () => {
368
  }, []);
369
 
370
  const addPrologue = useCallback(() => {
371
- if (conversationId === '') {
372
  const prologue = dialog.prompt_config?.prologue;
373
 
374
  const nextMessage = {
 
264
  const prologue = currentDialog?.prompt_config?.prologue ?? '';
265
 
266
  const addTemporaryConversation = useCallback(() => {
267
+ setList((pre) => {
268
+ if (dialogId) {
269
+ const nextList = [
270
+ {
271
+ id: '',
272
+ name: 'New conversation',
273
+ dialog_id: dialogId,
274
+ message: [
275
+ {
276
+ content: prologue,
277
+ role: MessageType.Assistant,
278
+ },
279
+ ],
280
+ } as IConversation,
281
+ ...conversationList,
282
+ ];
283
+ return nextList;
284
+ }
285
+
286
+ return pre;
287
  });
288
  }, [conversationList, dialogId, prologue]);
289
 
 
372
  }, []);
373
 
374
  const addPrologue = useCallback(() => {
375
+ if (dialogId !== '' && conversationId === '') {
376
  const prologue = dialog.prompt_config?.prologue;
377
 
378
  const nextMessage = {
web/src/pages/chat/index.tsx CHANGED
@@ -239,7 +239,7 @@ const Chat = () => {
239
  >
240
  <Space>
241
  <b>Chat</b>
242
- <Tag>25</Tag>
243
  </Space>
244
  <Dropdown menu={{ items }}>
245
  <FormOutlined />
 
239
  >
240
  <Space>
241
  <b>Chat</b>
242
+ <Tag>{conversationList.length}</Tag>
243
  </Space>
244
  <Dropdown menu={{ items }}>
245
  <FormOutlined />
web/src/pages/chat/model.ts CHANGED
@@ -59,20 +59,6 @@ const model: DvaModel<ChatModelState> = {
59
  currentConversation: { ...payload, message: messageList },
60
  };
61
  },
62
- addEmptyConversationToList(state, {}) {
63
- const list = [...state.conversationList];
64
- // if (list.every((x) => x.id !== 'empty')) {
65
- // list.push({
66
- // id: 'empty',
67
- // name: 'New conversation',
68
- // message: [],
69
- // });
70
- // }
71
- return {
72
- ...state,
73
- conversationList: list,
74
- };
75
- },
76
  },
77
 
78
  effects: {
@@ -100,7 +86,9 @@ const model: DvaModel<ChatModelState> = {
100
  },
101
  *listDialog({ payload }, { call, put }) {
102
  const { data } = yield call(chatService.listDialog, payload);
103
- yield put({ type: 'setDialogList', payload: data.data });
 
 
104
  },
105
  *listConversation({ payload }, { call, put }) {
106
  const { data } = yield call(chatService.listConversation, payload);
 
59
  currentConversation: { ...payload, message: messageList },
60
  };
61
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  },
63
 
64
  effects: {
 
86
  },
87
  *listDialog({ payload }, { call, put }) {
88
  const { data } = yield call(chatService.listDialog, payload);
89
+ if (data.retcode === 0) {
90
+ yield put({ type: 'setDialogList', payload: data.data });
91
+ }
92
  },
93
  *listConversation({ payload }, { call, put }) {
94
  const { data } = yield call(chatService.listConversation, payload);