fix input error

This commit is contained in:
pompurin404 2024-08-08 15:31:59 +08:00
parent 7f8e1ac386
commit bd37e38a66
No known key found for this signature in database
2 changed files with 18 additions and 2 deletions

View File

@ -13,6 +13,8 @@ import {
import { IoLogoGithub } from 'react-icons/io5' import { IoLogoGithub } from 'react-icons/io5'
import { version } from '@renderer/utils/init' import { version } from '@renderer/utils/init'
import useSWR from 'swr' import useSWR from 'swr'
import { useState } from 'react'
import debounce from '@renderer/utils/debounce'
const Settings: React.FC = () => { const Settings: React.FC = () => {
const { data: enable, mutate } = useSWR('checkAutoRun', checkAutoRun, { const { data: enable, mutate } = useSWR('checkAutoRun', checkAutoRun, {
@ -22,6 +24,7 @@ const Settings: React.FC = () => {
const { appConfig, patchAppConfig } = useAppConfig() const { appConfig, patchAppConfig } = useAppConfig()
const { silentStart = false, delayTestUrl, delayTestTimeout, autoCheckUpdate } = appConfig || {} const { silentStart = false, delayTestUrl, delayTestTimeout, autoCheckUpdate } = appConfig || {}
const [url, setUrl] = useState(delayTestUrl)
return ( return (
<BasePage <BasePage
@ -77,10 +80,13 @@ const Settings: React.FC = () => {
<Input <Input
size="sm" size="sm"
className="w-[60%]" className="w-[60%]"
value={delayTestUrl} value={url}
placeholder="默认https://www.gstatic.com/generate_204" placeholder="默认https://www.gstatic.com/generate_204"
onValueChange={(v) => { onValueChange={(v) => {
setUrl(v)
debounce(() => {
patchAppConfig({ delayTestUrl: v }) patchAppConfig({ delayTestUrl: v })
}, 2000)
}} }}
></Input> ></Input>
</SettingItem> </SettingItem>

View File

@ -0,0 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export default function debounce<T extends (...args: any[]) => void>(func: T, wait: number): T {
let timeout: ReturnType<typeof setTimeout> | null = null
return function (this: any, ...args: Parameters<T>) {
if (timeout !== null) {
clearTimeout(timeout)
}
timeout = setTimeout(() => func.apply(this, args), wait)
} as T
}