mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +08:00
fix input error
This commit is contained in:
parent
7f8e1ac386
commit
bd37e38a66
@ -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) => {
|
||||||
patchAppConfig({ delayTestUrl: v })
|
setUrl(v)
|
||||||
|
debounce(() => {
|
||||||
|
patchAppConfig({ delayTestUrl: v })
|
||||||
|
}, 2000)
|
||||||
}}
|
}}
|
||||||
></Input>
|
></Input>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|||||||
10
src/renderer/src/utils/debounce.ts
Normal file
10
src/renderer/src/utils/debounce.ts
Normal 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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user