mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 10:52:08 +08:00
refactor(ui): share the switch adapter and drop dead memos
Three settings files each defined the same boolean switch-format adapter; it is exported once from the Switch module. The update dialog memoized trivial arithmetic, the profile-more reset callback keyed on a per-render document object instead of its stable setter, and the profile viewer's imperative handle had no dependency array.
This commit is contained in:
@@ -5,7 +5,13 @@ import { useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { updateGeo, type LogLevel } from 'tauri-plugin-mihomo-api'
|
||||
|
||||
import { BaseDialog, DialogRef, Switch, TooltipIcon } from '@/components/base'
|
||||
import {
|
||||
BaseDialog,
|
||||
DialogRef,
|
||||
Switch,
|
||||
TooltipIcon,
|
||||
switchChangeValue,
|
||||
} from '@/components/base'
|
||||
import { useClash } from '@/hooks/use-clash'
|
||||
import { useClashLog } from '@/hooks/use-clash-log'
|
||||
import { useDisplayedMixedPort } from '@/hooks/use-displayed-mixed-port'
|
||||
@@ -69,7 +75,6 @@ const SettingClash = ({ onError }: Props) => {
|
||||
const corsRef = useRef<DialogRef>(null)
|
||||
const tunnelRef = useRef<DialogRef>(null)
|
||||
|
||||
const onSwitchFormat = (_e: any, value: boolean) => value
|
||||
const onChangeData = (patch: Partial<IConfigData>) => {
|
||||
mutateClash((old) => ({ ...old!, ...patch }), false)
|
||||
}
|
||||
@@ -173,7 +178,7 @@ const SettingClash = ({ onError }: Props) => {
|
||||
value={allowLan ?? false}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ 'allow-lan': e })}
|
||||
onGuard={(e) => patchClash({ 'allow-lan': e })}
|
||||
>
|
||||
@@ -213,7 +218,7 @@ const SettingClash = ({ onError }: Props) => {
|
||||
value={ipv6 ?? false}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ ipv6: e })}
|
||||
onGuard={(e) => patchClash({ ipv6: e })}
|
||||
>
|
||||
@@ -235,7 +240,7 @@ const SettingClash = ({ onError }: Props) => {
|
||||
value={unifiedDelay ?? false}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ 'unified-delay': e })}
|
||||
onGuard={(e) => patchClash({ 'unified-delay': e })}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user