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)
|
||||
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
const debouncedEstimate = useCallback(
|
||||
(newText: string) => {
|
||||
debounce((newText) => {
|
||||
if (showInputEstimatedTokens) {
|
||||
const count = estimateTxtTokens(newText) || 0
|
||||
setTokenCount(count)
|
||||
}
|
||||
},
|
||||
}, 500),
|
||||
[showInputEstimatedTokens]
|
||||
)
|
||||
|
||||
const debouncedEstimateWithDelay = debounce(debouncedEstimate, 500)
|
||||
|
||||
useEffect(() => {
|
||||
debouncedEstimateWithDelay(text)
|
||||
return () => debouncedEstimateWithDelay.cancel()
|
||||
}, [text, debouncedEstimateWithDelay])
|
||||
debouncedEstimate(text)
|
||||
}, [text, debouncedEstimate])
|
||||
|
||||
const inputTokenCount = showInputEstimatedTokens ? tokenCount : 0
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { FormOutlined } from '@ant-design/icons'
|
||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||
import { EventEmitter } from '@renderer/services/EventService'
|
||||
import { EVENT_NAMES } from '@renderer/services/EventService'
|
||||
import { ThemeMode } from '@renderer/types'
|
||||
import { Button as AntdButton } from 'antd'
|
||||
import { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -8,6 +10,7 @@ import styled from 'styled-components'
|
||||
|
||||
const NewTopicButton: FC = () => {
|
||||
const { t } = useTranslation()
|
||||
const { theme } = useTheme()
|
||||
|
||||
const addNewTopic = () => {
|
||||
EventEmitter.emit(EVENT_NAMES.ADD_NEW_TOPIC)
|
||||
@ -15,7 +18,7 @@ const NewTopicButton: FC = () => {
|
||||
|
||||
return (
|
||||
<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')}
|
||||
</Button>
|
||||
</Container>
|
||||
@ -28,18 +31,18 @@ const Container = styled.div`
|
||||
align-items: center;
|
||||
`
|
||||
|
||||
const Button = styled(AntdButton)`
|
||||
const Button = styled(AntdButton)<{ $theme: ThemeMode }>`
|
||||
border-radius: 20px;
|
||||
padding: 0 12px;
|
||||
height: 34px !important;
|
||||
font-size: 12px;
|
||||
opacity: 0.8;
|
||||
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);
|
||||
&:hover {
|
||||
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;
|
||||
border-color: var(--color-border-mute) !important;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user