-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ style: upload image to vision model adapting to mobile device (#457)
* ✨ style: 上传图片适配移动端
- Loading branch information
Showing
9 changed files
with
191 additions
and
182 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
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 { memo } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import FileList from '@/app/chat/components/FileList'; | ||
import { useFileStore } from '@/store/files'; | ||
|
||
const Files = memo(() => { | ||
const inputFilesList = useFileStore((s) => s.inputFilesList); | ||
|
||
return ( | ||
<Flexbox padding={12}> | ||
<FileList alwaysShowClose items={inputFilesList} /> | ||
</Flexbox> | ||
); | ||
}); | ||
|
||
export default Files; |
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,79 +1,25 @@ | ||
import { Icon, Input } from '@lobehub/ui'; | ||
import { Button, type InputRef } from 'antd'; | ||
import { Loader2, SendHorizonal } from 'lucide-react'; | ||
import { forwardRef, useCallback, useRef } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { memo } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
import useControlledState from 'use-merge-value'; | ||
|
||
import ActionBar from '@/app/chat/features/ChatInput/ActionBar'; | ||
import InputAreaInner from '@/app/chat/features/ChatInput/InputAreaInner'; | ||
import SaveTopic from '@/app/chat/features/ChatInput/Topic'; | ||
|
||
import SendButton from './SendButton'; | ||
import { useStyles } from './style.mobile'; | ||
|
||
export type ChatInputAreaMobile = { | ||
loading?: boolean; | ||
onChange?: (value: string) => void; | ||
onSend?: (value: string) => void; | ||
onStop?: () => void; | ||
value?: string; | ||
}; | ||
const ChatInputArea = memo(() => { | ||
const { cx, styles } = useStyles(); | ||
|
||
const ChatInputArea = forwardRef<InputRef, ChatInputAreaMobile>( | ||
({ onSend, loading, onChange, onStop, value }) => { | ||
const { t } = useTranslation('chat'); | ||
const [currentValue, setCurrentValue] = useControlledState<string>('', { | ||
onChange: onChange, | ||
value, | ||
}); | ||
const { cx, styles } = useStyles(); | ||
const isChineseInput = useRef(false); | ||
|
||
const handleSend = useCallback(() => { | ||
if (loading) return; | ||
if (onSend) onSend(currentValue); | ||
setCurrentValue(''); | ||
}, [currentValue]); | ||
|
||
return ( | ||
<Flexbox className={cx(styles.container)} gap={12}> | ||
<ActionBar rightAreaStartRender={<SaveTopic />} /> | ||
<Flexbox className={styles.inner} gap={8} horizontal> | ||
<Input | ||
className={cx(styles.input)} | ||
onBlur={(e) => { | ||
setCurrentValue(e.target.value); | ||
}} | ||
onChange={(e) => { | ||
setCurrentValue(e.target.value); | ||
}} | ||
onCompositionEnd={() => { | ||
isChineseInput.current = false; | ||
}} | ||
onCompositionStart={() => { | ||
isChineseInput.current = true; | ||
}} | ||
onPressEnter={(e) => { | ||
if (!loading && !e.shiftKey && !isChineseInput.current) { | ||
e.preventDefault(); | ||
handleSend(); | ||
} | ||
}} | ||
placeholder={t('sendPlaceholder')} | ||
type={'block'} | ||
value={currentValue} | ||
/> | ||
<div> | ||
{loading ? ( | ||
<Button icon={loading && <Icon icon={Loader2} spin />} onClick={onStop} /> | ||
) : ( | ||
<Button icon={<Icon icon={SendHorizonal} />} onClick={handleSend} type={'primary'} /> | ||
)} | ||
</div> | ||
</Flexbox> | ||
return ( | ||
<Flexbox className={cx(styles.container)} gap={12}> | ||
<ActionBar rightAreaStartRender={<SaveTopic />} /> | ||
<Flexbox className={styles.inner} gap={8} horizontal> | ||
<InputAreaInner mobile /> | ||
<SendButton /> | ||
</Flexbox> | ||
); | ||
}, | ||
); | ||
</Flexbox> | ||
); | ||
}); | ||
|
||
export default ChatInputArea; |
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,30 @@ | ||
import { Icon } from '@lobehub/ui'; | ||
import { Button } from 'antd'; | ||
import { Loader2, SendHorizonal } from 'lucide-react'; | ||
import { memo } from 'react'; | ||
|
||
import { useSendMessage } from '@/app/chat/features/ChatInput/useSend'; | ||
import { useSessionStore } from '@/store/session'; | ||
|
||
const SendButton = memo(() => { | ||
const [loading, onStop] = useSessionStore((s) => [!!s.chatLoadingId, s.stopGenerateMessage]); | ||
|
||
const handleSend = useSendMessage(); | ||
|
||
return loading ? ( | ||
<Button | ||
icon={loading && <Icon icon={Loader2} spin />} | ||
onClick={onStop} | ||
style={{ flex: 'none' }} | ||
/> | ||
) : ( | ||
<Button | ||
icon={<Icon icon={SendHorizonal} />} | ||
onClick={handleSend} | ||
style={{ flex: 'none' }} | ||
type={'primary'} | ||
/> | ||
); | ||
}); | ||
|
||
export default SendButton; |
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
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.