mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 14:29:15 +08:00
refactor: optimize Inputbar debounce logic and enhance NewTopicButton styling
- Simplified the debounce implementation in the Inputbar component by removing an unnecessary wrapper. - Updated the NewTopicButton to utilize theme context for dynamic styling based on the current theme.
This commit is contained in:
parent
893a04aba3
commit
cef32f4b36
@ -106,22 +106,20 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
|||||||
|
|
||||||
const [mentionFromKeyboard, setMentionFromKeyboard] = useState(false)
|
const [mentionFromKeyboard, setMentionFromKeyboard] = useState(false)
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
const debouncedEstimate = useCallback(
|
const debouncedEstimate = useCallback(
|
||||||
(newText: string) => {
|
debounce((newText) => {
|
||||||
if (showInputEstimatedTokens) {
|
if (showInputEstimatedTokens) {
|
||||||
const count = estimateTxtTokens(newText) || 0
|
const count = estimateTxtTokens(newText) || 0
|
||||||
setTokenCount(count)
|
setTokenCount(count)
|
||||||
}
|
}
|
||||||
},
|
}, 500),
|
||||||
[showInputEstimatedTokens]
|
[showInputEstimatedTokens]
|
||||||
)
|
)
|
||||||
|
|
||||||
const debouncedEstimateWithDelay = debounce(debouncedEstimate, 500)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
debouncedEstimateWithDelay(text)
|
debouncedEstimate(text)
|
||||||
return () => debouncedEstimateWithDelay.cancel()
|
}, [text, debouncedEstimate])
|
||||||
}, [text, debouncedEstimateWithDelay])
|
|
||||||
|
|
||||||
const inputTokenCount = showInputEstimatedTokens ? tokenCount : 0
|
const inputTokenCount = showInputEstimatedTokens ? tokenCount : 0
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { FormOutlined } from '@ant-design/icons'
|
import { FormOutlined } from '@ant-design/icons'
|
||||||
|
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||||
import { EventEmitter } from '@renderer/services/EventService'
|
import { EventEmitter } from '@renderer/services/EventService'
|
||||||
import { EVENT_NAMES } from '@renderer/services/EventService'
|
import { EVENT_NAMES } from '@renderer/services/EventService'
|
||||||
|
import { ThemeMode } from '@renderer/types'
|
||||||
import { Button as AntdButton } from 'antd'
|
import { Button as AntdButton } from 'antd'
|
||||||
import { FC } from 'react'
|
import { FC } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -8,6 +10,7 @@ import styled from 'styled-components'
|
|||||||
|
|
||||||
const NewTopicButton: FC = () => {
|
const NewTopicButton: FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { theme } = useTheme()
|
||||||
|
|
||||||
const addNewTopic = () => {
|
const addNewTopic = () => {
|
||||||
EventEmitter.emit(EVENT_NAMES.ADD_NEW_TOPIC)
|
EventEmitter.emit(EVENT_NAMES.ADD_NEW_TOPIC)
|
||||||
@ -15,7 +18,7 @@ const NewTopicButton: FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Button size="small" color="primary" icon={<FormOutlined />} onClick={addNewTopic}>
|
<Button size="small" color="primary" icon={<FormOutlined />} onClick={addNewTopic} $theme={theme}>
|
||||||
{t('chat.topics.new')}
|
{t('chat.topics.new')}
|
||||||
</Button>
|
</Button>
|
||||||
</Container>
|
</Container>
|
||||||
@ -28,18 +31,18 @@ const Container = styled.div`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
`
|
`
|
||||||
|
|
||||||
const Button = styled(AntdButton)`
|
const Button = styled(AntdButton)<{ $theme: ThemeMode }>`
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
padding: 0 12px;
|
padding: 0 12px;
|
||||||
height: 34px !important;
|
height: 34px !important;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
background-color: var(--color-background-soft);
|
background-color: ${(props) => (props.$theme === ThemeMode.dark ? 'var(--color-background-soft)' : '')};
|
||||||
color: var(--color-text-2);
|
color: var(--color-text-2);
|
||||||
&:hover {
|
&:hover {
|
||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
background-color: var(--color-background-mute) !important;
|
background-color: ${(props) => (props.$theme === ThemeMode.dark ? 'var(--color-background-mute)' : '')} !important;
|
||||||
color: var(--color-text-1) !important;
|
color: var(--color-text-1) !important;
|
||||||
border-color: var(--color-border-mute) !important;
|
border-color: var(--color-border-mute) !important;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user