-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ perf: refactor to improve chat performance (#4708)
* ⚡️ perf: refactor to improve chat performance * ⚡️ perf: refactor to improve chat performance
- Loading branch information
Showing
16 changed files
with
400 additions
and
270 deletions.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/TextArea.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,29 @@ | ||
import { memo } from 'react'; | ||
|
||
import InputArea from '@/features/ChatInput/Desktop/InputArea'; | ||
import { useSendMessage } from '@/features/ChatInput/useSend'; | ||
import { useChatStore } from '@/store/chat'; | ||
import { chatSelectors } from '@/store/chat/slices/message/selectors'; | ||
|
||
const TextArea = memo<{ onSend?: () => void }>(({ onSend }) => { | ||
const [loading, value, updateInputMessage] = useChatStore((s) => [ | ||
chatSelectors.isAIGenerating(s), | ||
s.inputMessage, | ||
s.updateInputMessage, | ||
]); | ||
const { send: sendMessage } = useSendMessage(); | ||
|
||
return ( | ||
<InputArea | ||
loading={loading} | ||
onChange={updateInputMessage} | ||
onSend={() => { | ||
sendMessage(); | ||
onSend?.(); | ||
}} | ||
value={value} | ||
/> | ||
); | ||
}); | ||
|
||
export default TextArea; |
46 changes: 46 additions & 0 deletions
46
src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/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,46 @@ | ||
'use client'; | ||
|
||
import { memo } from 'react'; | ||
|
||
import { ActionKeys } from '@/features/ChatInput/ActionBar/config'; | ||
import DesktopChatInput from '@/features/ChatInput/Desktop'; | ||
import { useGlobalStore } from '@/store/global'; | ||
import { systemStatusSelectors } from '@/store/global/selectors'; | ||
|
||
import TextArea from './TextArea'; | ||
|
||
const leftActions = [ | ||
'model', | ||
'fileUpload', | ||
'knowledgeBase', | ||
'temperature', | ||
'history', | ||
'stt', | ||
'tools', | ||
'token', | ||
] as ActionKeys[]; | ||
|
||
const rightActions = ['clear'] as ActionKeys[]; | ||
|
||
const renderTextArea = (onSend: () => void) => <TextArea onSend={onSend} />; | ||
|
||
const Desktop = memo(() => { | ||
const [inputHeight, updatePreference] = useGlobalStore((s) => [ | ||
systemStatusSelectors.inputHeight(s), | ||
s.updateSystemStatus, | ||
]); | ||
|
||
return ( | ||
<DesktopChatInput | ||
inputHeight={inputHeight} | ||
leftActions={leftActions} | ||
onInputHeightChange={(height) => { | ||
updatePreference({ inputHeight: height }); | ||
}} | ||
renderTextArea={renderTextArea} | ||
rightActions={rightActions} | ||
/> | ||
); | ||
}); | ||
|
||
export default Desktop; |
3 changes: 2 additions & 1 deletion
3
src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export const LOADING_FLAT = '...'; | ||
|
||
export const MESSAGE_CANCEL_FLAT = 'canceled'; | ||
|
||
export const MESSAGE_THREAD_DIVIDER_ID = 'thread-divider'; | ||
|
||
export const MESSAGE_WELCOME_GUIDE_ID = 'welcome'; |
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,61 @@ | ||
import { Icon } from '@lobehub/ui'; | ||
import { Skeleton } from 'antd'; | ||
import { useTheme } from 'antd-style'; | ||
import { ChevronUp, CornerDownLeft, LucideCommand } from 'lucide-react'; | ||
import { memo, useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Center, Flexbox } from 'react-layout-kit'; | ||
|
||
import { useUserStore } from '@/store/user'; | ||
import { preferenceSelectors } from '@/store/user/selectors'; | ||
import { isMacOS } from '@/utils/platform'; | ||
|
||
const ShortcutHint = memo(() => { | ||
const { t } = useTranslation('chat'); | ||
const theme = useTheme(); | ||
const useCmdEnterToSend = useUserStore(preferenceSelectors.useCmdEnterToSend); | ||
const [isMac, setIsMac] = useState<boolean>(); | ||
|
||
useEffect(() => { | ||
setIsMac(isMacOS()); | ||
}, []); | ||
|
||
const cmdEnter = ( | ||
<Flexbox gap={2} horizontal> | ||
{typeof isMac === 'boolean' ? ( | ||
<Icon icon={isMac ? LucideCommand : ChevronUp} /> | ||
) : ( | ||
<Skeleton.Node active style={{ height: '100%', width: 12 }}> | ||
{' '} | ||
</Skeleton.Node> | ||
)} | ||
<Icon icon={CornerDownLeft} /> | ||
</Flexbox> | ||
); | ||
|
||
const enter = ( | ||
<Center> | ||
<Icon icon={CornerDownLeft} /> | ||
</Center> | ||
); | ||
|
||
const sendShortcut = useCmdEnterToSend ? cmdEnter : enter; | ||
|
||
const wrapperShortcut = useCmdEnterToSend ? enter : cmdEnter; | ||
|
||
return ( | ||
<Flexbox | ||
gap={4} | ||
horizontal | ||
style={{ color: theme.colorTextDescription, fontSize: 12, marginRight: 12 }} | ||
> | ||
{sendShortcut} | ||
<span>{t('input.send')}</span> | ||
<span>/</span> | ||
{wrapperShortcut} | ||
<span>{t('input.warp')}</span> | ||
</Flexbox> | ||
); | ||
}); | ||
|
||
export default ShortcutHint; |
Oops, something went wrong.