forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: refactor the main chat (lobehub#4773)
* ♻️ refactor: refactor the main chat * ♻️ refactor: refactor welcome
- Loading branch information
Showing
36 changed files
with
541 additions
and
524 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/app/(main)/chat/(workspace)/@conversation/features/ChatList/ChatItem/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { memo, useMemo } from 'react'; | ||
|
||
import { ChatItem } from '@/features/Conversation'; | ||
import ActionsBar from '@/features/Conversation/components/ChatItem/ActionsBar'; | ||
import { useAgentStore } from '@/store/agent'; | ||
import { agentSelectors } from '@/store/agent/selectors'; | ||
import { useChatStore } from '@/store/chat'; | ||
import { chatSelectors } from '@/store/chat/selectors'; | ||
|
||
export interface ThreadChatItemProps { | ||
id: string; | ||
index: number; | ||
} | ||
|
||
const MainChatItem = memo<ThreadChatItemProps>(({ id, index }) => { | ||
const [historyLength] = useChatStore((s) => [chatSelectors.mainDisplayChatIDs(s).length]); | ||
|
||
const enableHistoryDivider = useAgentStore((s) => { | ||
const config = agentSelectors.currentAgentChatConfig(s); | ||
return ( | ||
config.enableHistoryCount && | ||
historyLength > (config.historyCount ?? 0) && | ||
config.historyCount === historyLength - index | ||
); | ||
}); | ||
|
||
const actionBar = useMemo(() => <ActionsBar id={id} />, [id]); | ||
|
||
return ( | ||
<ChatItem | ||
actionBar={actionBar} | ||
enableHistoryDivider={enableHistoryDivider} | ||
id={id} | ||
index={index} | ||
/> | ||
); | ||
}); | ||
|
||
export default MainChatItem; |
34 changes: 20 additions & 14 deletions
34
src/app/(main)/chat/(workspace)/@conversation/features/ChatList/Content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions
44
...main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem/WelcomeMessage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ChatItem } from '@lobehub/ui'; | ||
import isEqual from 'fast-deep-equal'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { useAgentStore } from '@/store/agent'; | ||
import { agentSelectors } from '@/store/agent/selectors'; | ||
import { useChatStore } from '@/store/chat'; | ||
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig'; | ||
import { useSessionStore } from '@/store/session'; | ||
import { sessionMetaSelectors } from '@/store/session/selectors'; | ||
|
||
const WelcomeMessage = () => { | ||
const { t } = useTranslation('chat'); | ||
const [type = 'chat'] = useAgentStore((s) => { | ||
const config = agentSelectors.currentAgentChatConfig(s); | ||
return [config.displayMode]; | ||
}); | ||
|
||
const meta = useSessionStore(sessionMetaSelectors.currentAgentMeta, isEqual); | ||
const { isAgentEditable } = useServerConfigStore(featureFlagsSelectors); | ||
const activeId = useChatStore((s) => s.activeId); | ||
|
||
const agentSystemRoleMsg = t('agentDefaultMessageWithSystemRole', { | ||
name: meta.title || t('defaultAgent'), | ||
systemRole: meta.description, | ||
}); | ||
|
||
const agentMsg = t(isAgentEditable ? 'agentDefaultMessage' : 'agentDefaultMessageWithoutEdit', { | ||
name: meta.title || t('defaultAgent'), | ||
url: `/chat/settings?session=${activeId}`, | ||
}); | ||
|
||
return ( | ||
<ChatItem | ||
avatar={meta} | ||
editing={false} | ||
message={!!meta.description ? agentSystemRoleMsg : agentMsg} | ||
placement={'left'} | ||
type={type === 'chat' ? 'block' : 'pure'} | ||
/> | ||
); | ||
}; | ||
export default WelcomeMessage; |
17 changes: 17 additions & 0 deletions
17
src/app/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { memo } from 'react'; | ||
|
||
import { useChatStore } from '@/store/chat'; | ||
import { chatSelectors } from '@/store/chat/selectors'; | ||
|
||
import InboxWelcome from './InboxWelcome'; | ||
import WelcomeMessage from './WelcomeMessage'; | ||
|
||
const WelcomeChatItem = memo(() => { | ||
const showInboxWelcome = useChatStore(chatSelectors.showInboxWelcome); | ||
|
||
if (showInboxWelcome) return <InboxWelcome />; | ||
|
||
return <WelcomeMessage />; | ||
}); | ||
|
||
export default WelcomeChatItem; |
14 changes: 1 addition & 13 deletions
14
src/app/(main)/chat/(workspace)/@portal/features/Header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
'use client'; | ||
|
||
import { ActionIcon } from '@lobehub/ui'; | ||
import { XIcon } from 'lucide-react'; | ||
import { memo } from 'react'; | ||
|
||
import SidebarHeader from '@/components/SidebarHeader'; | ||
import { PortalHeader } from '@/features/Portal/router'; | ||
import { useChatStore } from '@/store/chat'; | ||
|
||
const Header = memo(() => { | ||
const [toggleInspector] = useChatStore((s) => [s.togglePortal]); | ||
|
||
return ( | ||
<SidebarHeader | ||
actions={<ActionIcon icon={XIcon} onClick={() => toggleInspector(false)} />} | ||
style={{ paddingBlock: 8, paddingInline: 8 }} | ||
title={<PortalHeader />} | ||
/> | ||
); | ||
return <PortalHeader />; | ||
}); | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.