[优化] 优化界面

This commit is contained in:
ryan
2026-06-01 11:11:48 +08:00
parent 77bdb8bf0e
commit 7372ac230b
2 changed files with 10 additions and 5 deletions
@@ -1,6 +1,6 @@
'use client'; 'use client';
import { useEffect } from 'react'; import { useEffect, useRef } from 'react';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { cn } from '@/lib/utils/cn'; import { cn } from '@/lib/utils/cn';
@@ -27,9 +27,15 @@ export function InlineMessage({
className, className,
onClear, onClear,
}: InlineMessageProps) { }: InlineMessageProps) {
const onClearRef = useRef(onClear);
useEffect(() => {
onClearRef.current = onClear;
}, [onClear]);
useEffect(() => { useEffect(() => {
// Only trigger toast if onClear is provided (dynamic feedback) // Only trigger toast if onClear is provided (dynamic feedback)
if (!onClear || !message) return; if (!onClearRef.current || !message) return;
const options = { const options = {
position: 'bottom-right' as const, position: 'bottom-right' as const,
@@ -44,10 +50,10 @@ export function InlineMessage({
} }
const timer = setTimeout(() => { const timer = setTimeout(() => {
onClear(); onClearRef.current?.();
}, 0); }, 0);
return () => clearTimeout(timer); return () => clearTimeout(timer);
}, [tone, message, onClear]); }, [tone, message]);
// If onClear is provided, this is a toast feedback notice, so render nothing inline // If onClear is provided, this is a toast feedback notice, so render nothing inline
if (onClear) { if (onClear) {
@@ -2,7 +2,6 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import Link from 'next/link';
import { EmptyState } from '@/components/feedback/empty-state'; import { EmptyState } from '@/components/feedback/empty-state';
import { ErrorState } from '@/components/feedback/error-state'; import { ErrorState } from '@/components/feedback/error-state';