Skip to content

Commit

Permalink
fix: Fix new conversation force refresh experience issue
Browse files Browse the repository at this point in the history
  • Loading branch information
songsz committed Mar 15, 2024
1 parent f340a41 commit 62a91a7
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/pages/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { useModel } from '@@/exports';
import { history } from '@umijs/max';
import ChatComponent from '@yuntijs/chat';
import React, { useCallback, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import useConversationList, { setQueryConversationId } from '@/pages/Chat/useConversationList';

Expand All @@ -33,6 +33,27 @@ const Chat: React.FC<IChat> = props => {
},
[setNewConversationId]
);

// Fix new conversation force refresh experience issue
const refresh = useMemo(() => {
if (!selectedConversationId) {
return '';
}
if (newConversationId) {
return '';
}
return selectedConversationId;
}, [newConversationId, selectedConversationId]);
useEffect(() => {
if (
newConversationId &&
selectedConversationId &&
newConversationId !== selectedConversationId
) {
setNewConversationId();
}
}, [newConversationId, selectedConversationId, setNewConversationId]);

const { qiankun }: { qiankun: Record<string, any> } = useModel('qiankun');
return (
<div className="chatContainer">
Expand All @@ -44,7 +65,7 @@ const Chat: React.FC<IChat> = props => {
conversationId={selectedConversationId}
isDark={qiankun?.theme?.isDark}
onNewChat={onNewChat}
refresh={selectedConversationId || selectedConversationIdEmpty}
refresh={refresh}
/>
</div>
</div>
Expand Down

0 comments on commit 62a91a7

Please sign in to comment.