From f74ac9ff542c21f0b8600734eb0dc5defe7626cb Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Tue, 9 Dec 2025 03:23:21 +0800 Subject: [PATCH] fix: Fixed the class name format of the status indicator in the PortForwarding component and optimized the code format of the ToastProvider component --- components/PortForwardingNew.tsx | 4 +- components/ui/toast.tsx | 182 +++++++++++++++---------------- 2 files changed, 93 insertions(+), 93 deletions(-) diff --git a/components/PortForwardingNew.tsx b/components/PortForwardingNew.tsx index 6d1d95f28..74f82f210 100644 --- a/components/PortForwardingNew.tsx +++ b/components/PortForwardingNew.tsx @@ -464,14 +464,14 @@ const PortForwarding: React.FC = ({ hosts, keys, customGrou
{rule.label} -
diff --git a/components/ui/toast.tsx b/components/ui/toast.tsx index e3333af30..b793c9d6b 100644 --- a/components/ui/toast.tsx +++ b/components/ui/toast.tsx @@ -5,130 +5,130 @@ import { X, AlertCircle, CheckCircle, Info, AlertTriangle } from 'lucide-react'; export type ToastType = 'success' | 'error' | 'warning' | 'info'; export interface Toast { - id: string; - type: ToastType; - title?: string; - message: string; - duration?: number; + id: string; + type: ToastType; + title?: string; + message: string; + duration?: number; } interface ToastContextValue { - toasts: Toast[]; - showToast: (toast: Omit) => void; - dismissToast: (id: string) => void; + toasts: Toast[]; + showToast: (toast: Omit) => void; + dismissToast: (id: string) => void; } const ToastContext = createContext(null); export const useToast = () => { - const context = useContext(ToastContext); - if (!context) { - throw new Error('useToast must be used within a ToastProvider'); - } - return context; + const context = useContext(ToastContext); + if (!context) { + throw new Error('useToast must be used within a ToastProvider'); + } + return context; }; // Simple hook for components that may not be inside ToastProvider let globalShowToast: ((toast: Omit) => void) | null = null; export const toast = { - success: (message: string, title?: string) => { - globalShowToast?.({ type: 'success', message, title, duration: 3000 }); - }, - error: (message: string, title?: string) => { - globalShowToast?.({ type: 'error', message, title, duration: 5000 }); - }, - warning: (message: string, title?: string) => { - globalShowToast?.({ type: 'warning', message, title, duration: 4000 }); - }, - info: (message: string, title?: string) => { - globalShowToast?.({ type: 'info', message, title, duration: 3000 }); - }, + success: (message: string, title?: string) => { + globalShowToast?.({ type: 'success', message, title, duration: 3000 }); + }, + error: (message: string, title?: string) => { + globalShowToast?.({ type: 'error', message, title, duration: 5000 }); + }, + warning: (message: string, title?: string) => { + globalShowToast?.({ type: 'warning', message, title, duration: 4000 }); + }, + info: (message: string, title?: string) => { + globalShowToast?.({ type: 'info', message, title, duration: 3000 }); + }, }; const TOAST_ICONS: Record = { - success: , - error: , - warning: , - info: , + success: , + error: , + warning: , + info: , }; const TOAST_STYLES: Record = { - success: 'border-emerald-500/30 bg-emerald-500/10', - error: 'border-red-500/30 bg-red-500/10', - warning: 'border-yellow-500/30 bg-yellow-500/10', - info: 'border-blue-500/30 bg-blue-500/10', + success: 'border-emerald-500/30 bg-emerald-500/10', + error: 'border-red-500/30 bg-red-500/10', + warning: 'border-yellow-500/30 bg-yellow-500/10', + info: 'border-blue-500/30 bg-blue-500/10', }; export const ToastProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { - const [toasts, setToasts] = useState([]); + const [toasts, setToasts] = useState([]); - const showToast = useCallback((toast: Omit) => { - const id = `toast-${Date.now()}-${Math.random().toString(36).slice(2)}`; - const newToast: Toast = { ...toast, id }; - setToasts(prev => [...prev, newToast]); + const showToast = useCallback((toast: Omit) => { + const id = `toast-${Date.now()}-${Math.random().toString(36).slice(2)}`; + const newToast: Toast = { ...toast, id }; + setToasts(prev => [...prev, newToast]); - // Auto dismiss - if (toast.duration !== 0) { - setTimeout(() => { + // Auto dismiss + if (toast.duration !== 0) { + setTimeout(() => { + setToasts(prev => prev.filter(t => t.id !== id)); + }, toast.duration || 4000); + } + }, []); + + const dismissToast = useCallback((id: string) => { setToasts(prev => prev.filter(t => t.id !== id)); - }, toast.duration || 4000); - } - }, []); + }, []); - const dismissToast = useCallback((id: string) => { - setToasts(prev => prev.filter(t => t.id !== id)); - }, []); + // Register global toast function + useEffect(() => { + globalShowToast = showToast; + return () => { + globalShowToast = null; + }; + }, [showToast]); - // Register global toast function - useEffect(() => { - globalShowToast = showToast; - return () => { - globalShowToast = null; - }; - }, [showToast]); - - return ( - - {children} - - - ); + return ( + + {children} + + + ); }; const ToastContainer: React.FC<{ toasts: Toast[]; onDismiss: (id: string) => void }> = ({ toasts, onDismiss }) => { - if (toasts.length === 0) return null; + if (toasts.length === 0) return null; - return ( -
- {toasts.map(t => ( -
-
- {TOAST_ICONS[t.type]} -
-
- {t.title && ( -
{t.title}
- )} -
{t.message}
-
- + return ( +
+ {toasts.map(t => ( +
+
+ {TOAST_ICONS[t.type]} +
+
+ {t.title && ( +
{t.title}
+ )} +
{t.message}
+
+ +
+ ))}
- ))} -
- ); + ); }; export default ToastProvider;