mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-19 03:00:49 +08:00
fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useCallback, type PropsWithChildren, type ReactNode } from 'react';
|
import { useState, useEffect, useCallback, useRef, type PropsWithChildren, type ReactNode } from 'react';
|
||||||
import { IconX } from './icons';
|
import { IconX } from './icons';
|
||||||
|
|
||||||
interface ModalProps {
|
interface ModalProps {
|
||||||
@@ -14,22 +14,51 @@ const CLOSE_ANIMATION_DURATION = 350;
|
|||||||
export function Modal({ open, title, onClose, footer, width = 520, children }: PropsWithChildren<ModalProps>) {
|
export function Modal({ open, title, onClose, footer, width = 520, children }: PropsWithChildren<ModalProps>) {
|
||||||
const [isVisible, setIsVisible] = useState(false);
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
const [isClosing, setIsClosing] = useState(false);
|
const [isClosing, setIsClosing] = useState(false);
|
||||||
|
const closeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
|
||||||
|
const startClose = useCallback(
|
||||||
|
(notifyParent: boolean) => {
|
||||||
|
if (closeTimerRef.current !== null) return;
|
||||||
|
setIsClosing(true);
|
||||||
|
closeTimerRef.current = window.setTimeout(() => {
|
||||||
|
setIsVisible(false);
|
||||||
|
setIsClosing(false);
|
||||||
|
closeTimerRef.current = null;
|
||||||
|
if (notifyParent) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
}, CLOSE_ANIMATION_DURATION);
|
||||||
|
},
|
||||||
|
[onClose]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open) {
|
if (open) {
|
||||||
|
if (closeTimerRef.current !== null) {
|
||||||
|
window.clearTimeout(closeTimerRef.current);
|
||||||
|
closeTimerRef.current = null;
|
||||||
|
}
|
||||||
setIsVisible(true);
|
setIsVisible(true);
|
||||||
setIsClosing(false);
|
setIsClosing(false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, [open]);
|
|
||||||
|
if (isVisible) {
|
||||||
|
startClose(false);
|
||||||
|
}
|
||||||
|
}, [open, isVisible, startClose]);
|
||||||
|
|
||||||
const handleClose = useCallback(() => {
|
const handleClose = useCallback(() => {
|
||||||
setIsClosing(true);
|
startClose(true);
|
||||||
setTimeout(() => {
|
}, [startClose]);
|
||||||
setIsVisible(false);
|
|
||||||
setIsClosing(false);
|
useEffect(() => {
|
||||||
onClose();
|
return () => {
|
||||||
}, CLOSE_ANIMATION_DURATION);
|
if (closeTimerRef.current !== null) {
|
||||||
}, [onClose]);
|
window.clearTimeout(closeTimerRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (!open && !isVisible) return null;
|
if (!open && !isVisible) return null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user