mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 02:42:12 +08:00
fix(setting): keep the copy-success snackbar visible for its full duration
The clipboard handler cleared the success flag with a zero-delay timeout, so the snackbar configured for 2000 ms was hidden on the next macrotask. The clear now runs after 2000 ms, resetting the timer on each copy so a second copy within the window keeps its full duration.
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
Tooltip,
|
||||
} from '@mui/material'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import { useState, type Ref } from 'react'
|
||||
import { useRef, useState, type Ref } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { BaseDialog, DialogRef, Switch } from '@/components/base'
|
||||
@@ -26,6 +26,10 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
const { t } = useTranslation()
|
||||
const [open, setOpen] = useState(false)
|
||||
const [copySuccess, setCopySuccess] = useState<null | string>(null)
|
||||
// A second copy within the window must not be hidden by the first timer.
|
||||
const copySuccessTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(
|
||||
undefined,
|
||||
)
|
||||
const [isSaving, setIsSaving] = useState(false)
|
||||
|
||||
const { clashInfo, patchInfo } = useClashInfo()
|
||||
@@ -96,7 +100,11 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
setCopySuccess(type)
|
||||
setTimeout(() => setCopySuccess(null))
|
||||
clearTimeout(copySuccessTimerRef.current)
|
||||
copySuccessTimerRef.current = setTimeout(
|
||||
() => setCopySuccess(null),
|
||||
2000,
|
||||
)
|
||||
} catch (err) {
|
||||
console.warn('[ControllerViewer] copy to clipboard failed:', err)
|
||||
showNotice.error(
|
||||
|
||||
Reference in New Issue
Block a user