Skip to content

Commit 7e2f4ce

Browse files
💄 style: Open new topic by tap Just Chat again (lobehub#8311)
* feat: Open new topic by tap Just Chat again * feat: Prevent re-render of message update * fix: Import loop
1 parent ca5432e commit 7e2f4ce

File tree

2 files changed

+21
-2
lines changed
  • src
    • app/[variants]/(main)/chat/@session/features/SessionListContent/Inbox
    • store/chat/slices/message

2 files changed

+21
-2
lines changed

src/app/[variants]/(main)/chat/@session/features/SessionListContent/Inbox/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { DEFAULT_INBOX_AVATAR } from '@/const/meta';
66
import { INBOX_SESSION_ID } from '@/const/session';
77
import { SESSION_CHAT_URL } from '@/const/url';
88
import { useSwitchSession } from '@/hooks/useSwitchSession';
9+
import { getChatStoreState, useChatStore } from '@/store/chat';
10+
import { chatSelectors } from '@/store/chat/selectors';
911
import { useServerConfigStore } from '@/store/serverConfig';
1012
import { useSessionStore } from '@/store/session';
1113

@@ -17,13 +19,24 @@ const Inbox = memo(() => {
1719
const activeId = useSessionStore((s) => s.activeId);
1820
const switchSession = useSwitchSession();
1921

22+
const openNewTopicOrSaveTopic = useChatStore((s) => s.openNewTopicOrSaveTopic);
23+
2024
return (
2125
<Link
2226
aria-label={t('inbox.title')}
2327
href={SESSION_CHAT_URL(INBOX_SESSION_ID, mobile)}
24-
onClick={(e) => {
28+
onClick={async (e) => {
2529
e.preventDefault();
26-
switchSession(INBOX_SESSION_ID);
30+
if (activeId === INBOX_SESSION_ID) {
31+
// If user tap the inbox again, open a new topic
32+
const inboxMessages = chatSelectors.inboxActiveTopicMessages(getChatStoreState());
33+
34+
if (inboxMessages.length > 0) {
35+
await openNewTopicOrSaveTopic();
36+
}
37+
} else {
38+
switchSession(INBOX_SESSION_ID);
39+
}
2740
}}
2841
>
2942
<ListItem

src/store/chat/slices/message/selectors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ const isSendButtonDisabledByMessage = (s: ChatStoreState) =>
201201
// 4. when the message is in RAG flow
202202
isInRAGFlow(s);
203203

204+
const inboxActiveTopicMessages = (state: ChatStoreState) => {
205+
const activeTopicId = state.activeTopicId;
206+
return state.messagesMap[messageMapKey(INBOX_SESSION_ID, activeTopicId)] || [];
207+
};
208+
204209
export const chatSelectors = {
205210
activeBaseChats,
206211
activeBaseChatsWithoutTool,
@@ -213,6 +218,7 @@ export const chatSelectors = {
213218
getMessageById,
214219
getMessageByToolCallId,
215220
getTraceIdByMessageId,
221+
inboxActiveTopicMessages,
216222
isAIGenerating,
217223
isCreatingMessage,
218224
isCurrentChatLoaded,

0 commit comments

Comments
 (0)