fix: lint warning

This commit is contained in:
kangfenmao 2025-03-15 13:14:06 +08:00
parent 3f285d0676
commit d1087ec87c
10 changed files with 54 additions and 51 deletions

View File

@ -11,29 +11,27 @@ const Scrollbar: FC<Props> = forwardRef<HTMLDivElement, Props>((props, ref) => {
const [isScrolling, setIsScrolling] = useState(false) const [isScrolling, setIsScrolling] = useState(false)
const timeoutRef = useRef<NodeJS.Timeout | null>(null) const timeoutRef = useRef<NodeJS.Timeout | null>(null)
const handleScroll = useCallback( const handleScroll = useCallback(() => {
throttle(() => { setIsScrolling(true)
setIsScrolling(true)
if (timeoutRef.current) { if (timeoutRef.current) {
clearTimeout(timeoutRef.current) clearTimeout(timeoutRef.current)
} }
timeoutRef.current = setTimeout(() => setIsScrolling(false), 1500) // 增加到 2 秒 timeoutRef.current = setTimeout(() => setIsScrolling(false), 1500)
}, 200), }, [])
[]
) const throttledHandleScroll = throttle(handleScroll, 200)
useEffect(() => { useEffect(() => {
return () => { return () => {
if (timeoutRef.current) { timeoutRef.current && clearTimeout(timeoutRef.current)
clearTimeout(timeoutRef.current) throttledHandleScroll.cancel()
}
} }
}, []) }, [throttledHandleScroll])
return ( return (
<Container {...props} isScrolling={isScrolling} onScroll={handleScroll} ref={ref}> <Container {...props} isScrolling={isScrolling} onScroll={throttledHandleScroll} ref={ref}>
{props.children} {props.children}
</Container> </Container>
) )

View File

@ -88,7 +88,7 @@ const AgentsPage: FC = () => {
[t] [t]
) )
const getAgentFromSystemAgent = (agent: (typeof systemAgents)[number]) => { const getAgentFromSystemAgent = useCallback((agent: (typeof systemAgents)[number]) => {
return { return {
...omit(agent, 'group'), ...omit(agent, 'group'),
name: agent.name, name: agent.name,
@ -96,7 +96,7 @@ const AgentsPage: FC = () => {
topics: [], topics: [],
type: 'agent' type: 'agent'
} }
} }, [])
const getLocalizedGroupName = useCallback( const getLocalizedGroupName = useCallback(
(group: string) => { (group: string) => {
@ -121,7 +121,7 @@ const AgentsPage: FC = () => {
</Row> </Row>
) )
}, },
[onAddAgentConfirm] [getAgentFromSystemAgent, onAddAgentConfirm]
) )
const tabItems = useMemo(() => { const tabItems = useMemo(() => {

View File

@ -61,6 +61,7 @@ const PopupContainer: React.FC<Props> = ({ resolve }) => {
} }
} }
updateTokenCount() updateTokenCount()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [form.getFieldValue('prompt')]) }, [form.getFieldValue('prompt')])
const onFinish = (values: FieldType) => { const onFinish = (values: FieldType) => {

View File

@ -33,6 +33,7 @@ const HomePage: FC = () => {
useEffect(() => { useEffect(() => {
state?.assistant && setActiveAssistant(state?.assistant) state?.assistant && setActiveAssistant(state?.assistant)
state?.topic && setActiveTopic(state?.topic) state?.topic && setActiveTopic(state?.topic)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state]) }, [state])
useEffect(() => { useEffect(() => {

View File

@ -77,7 +77,6 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
const [expended, setExpend] = useState(false) const [expended, setExpend] = useState(false)
const [estimateTokenCount, setEstimateTokenCount] = useState(0) const [estimateTokenCount, setEstimateTokenCount] = useState(0)
const [contextCount, setContextCount] = useState({ current: 0, max: 0 }) const [contextCount, setContextCount] = useState({ current: 0, max: 0 })
// const generating = useAppSelector((state) => state.runtime.generating)
const textareaRef = useRef<TextAreaRef>(null) const textareaRef = useRef<TextAreaRef>(null)
const [files, setFiles] = useState<FileType[]>(_files) const [files, setFiles] = useState<FileType[]>(_files)
const { t } = useTranslation() const { t } = useTranslation()
@ -110,18 +109,21 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
const [mentionFromKeyboard, setMentionFromKeyboard] = useState(false) const [mentionFromKeyboard, setMentionFromKeyboard] = useState(false)
const debouncedEstimate = useCallback( const debouncedEstimate = useCallback(
debounce((newText) => { (newText: string) => {
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(() => {
debouncedEstimate(text) debouncedEstimateWithDelay(text)
}, [text, debouncedEstimate]) return () => debouncedEstimateWithDelay.cancel()
}, [text, debouncedEstimateWithDelay])
const inputTokenCount = showInputEstimatedTokens ? tokenCount : 0 const inputTokenCount = showInputEstimatedTokens ? tokenCount : 0
@ -438,7 +440,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
} }
} }
}, },
[pasteLongTextAsFile, pasteLongTextThreshold, supportExts, t, text] [model, pasteLongTextAsFile, pasteLongTextThreshold, resizeTextArea, supportExts, t, text]
) )
const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => { const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
@ -548,7 +550,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
}) })
] ]
return () => unsubscribes.forEach((unsub) => unsub()) return () => unsubscribes.forEach((unsub) => unsub())
}, [addNewTopic]) }, [addNewTopic, resizeTextArea])
useEffect(() => { useEffect(() => {
textareaRef.current?.focus() textareaRef.current?.focus()
@ -556,6 +558,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
useEffect(() => { useEffect(() => {
setTimeout(() => resizeTextArea(), 0) setTimeout(() => resizeTextArea(), 0)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])
useEffect(() => { useEffect(() => {

View File

@ -86,22 +86,19 @@ const MessageMenubar: FC<Props> = (props) => {
const handleResendUserMessage = useCallback( const handleResendUserMessage = useCallback(
async (messageUpdate?: Message) => { async (messageUpdate?: Message) => {
// messageUpdate 为了处理用户消息更改后的message if (!loading) {
if (loading) return const groupdMessages = messages.filter((m) => m.askId === message.id)
const groupdMessages = messages.filter((m) => m.askId === message.id)
// Resend all grouped messages // Resend all grouped messages
if (!isEmpty(groupdMessages)) { if (!isEmpty(groupdMessages)) {
// for (const assistantMessage of groupdMessages) { await resendMessage(message, assistant)
// const _model = assistantMessage.model || assistantModel return
await resendMessage(message, assistant) }
// }
return await resendMessage(messageUpdate ?? message, assistant)
} }
await resendMessage(messageUpdate ?? message, assistant)
}, },
[message, assistantModel, resendMessage, assistant, messages, loading] [message, resendMessage, assistant, messages, loading]
) )
const onEdit = useCallback(async () => { const onEdit = useCallback(async () => {

View File

@ -48,16 +48,8 @@ const Suggestions: FC<Props> = ({ assistant, messages }) => {
useEffect(() => { useEffect(() => {
suggestionsHandle() suggestionsHandle()
// const unsubscribes = [ // eslint-disable-next-line react-hooks/exhaustive-deps
// EventEmitter.on(EVENT_NAMES.RECEIVE_MESSAGE, async (msg: Message) => { }, [])
// ]
// return () => {
// for (const unsub of unsubscribes) {
// unsub()
// }
// }
}, []) // Remove messages dependency
useEffect(() => { useEffect(() => {
setSuggestions(suggestionsMap.get(messages[messages.length - 1]?.id) || []) setSuggestions(suggestionsMap.get(messages[messages.length - 1]?.id) || [])

View File

@ -182,6 +182,7 @@ const AssistantModelSettings: FC<Props> = ({ assistant, updateAssistant, updateA
useEffect(() => { useEffect(() => {
return () => updateAssistantSettings({ customParameters: customParametersRef.current }) return () => updateAssistantSettings({ customParameters: customParametersRef.current })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])
const formatSliderTooltip = (value?: number) => { const formatSliderTooltip = (value?: number) => {

View File

@ -324,8 +324,11 @@ const ProviderSetting: FC<Props> = ({ provider: _provider }) => {
</Space.Compact> </Space.Compact>
{isOpenAIProvider(provider) && ( {isOpenAIProvider(provider) && (
<SettingHelpTextRow style={{ justifyContent: 'space-between' }}> <SettingHelpTextRow style={{ justifyContent: 'space-between' }}>
<SettingHelpText style={{ marginLeft: 6, marginRight: "1em", whiteSpace: "break-spaces", wordBreak: "break-all" }}>{hostPreview()}</SettingHelpText> <SettingHelpText
<SettingHelpText style={{ minWidth: "fit-content" }}>{t('settings.provider.api.url.tip')}</SettingHelpText> style={{ marginLeft: 6, marginRight: '1em', whiteSpace: 'break-spaces', wordBreak: 'break-all' }}>
{hostPreview()}
</SettingHelpText>
<SettingHelpText style={{ minWidth: 'fit-content' }}>{t('settings.provider.api.url.tip')}</SettingHelpText>
</SettingHelpTextRow> </SettingHelpTextRow>
)} )}
{isAzureOpenAI && ( {isAzureOpenAI && (

View File

@ -4749,7 +4749,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"commander@npm:^2.8.1": "commander@npm:^2.19.0, commander@npm:^2.8.1":
version: 2.20.3 version: 2.20.3
resolution: "commander@npm:2.20.3" resolution: "commander@npm:2.20.3"
checksum: 10c0/74c781a5248c2402a0a3e966a0a2bba3c054aad144f5c023364be83265e796b20565aa9feff624132ff629aa64e16999fa40a743c10c12f7c61e96a794b99288 checksum: 10c0/74c781a5248c2402a0a3e966a0a2bba3c054aad144f5c023364be83265e796b20565aa9feff624132ff629aa64e16999fa40a743c10c12f7c61e96a794b99288
@ -9362,6 +9362,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"longest-streak@npm:^2.0.0":
version: 2.0.4
resolution: "longest-streak@npm:2.0.4"
checksum: 10c0/918fb5104cde537757f44431776d6d828bc091a63ca38a3b3e59a08b88498b4421bf5fd9823ef22b4d186f0234d9943087fa96bd6117d26dedcf6008480fd46a
languageName: node
linkType: hard
"longest-streak@npm:^3.0.0": "longest-streak@npm:^3.0.0":
version: 3.1.0 version: 3.1.0
resolution: "longest-streak@npm:3.1.0" resolution: "longest-streak@npm:3.1.0"