feat(webui): improve operation feedback

Keep confirmations in dialogs while showing clear progress and results for long-running actions.

Auto-close completed notices, preserve important outcomes across reloads, and avoid noise from routine edits.
This commit is contained in:
DrSmoothl committed 2026-07-31 15:35:03 +08:00
1 parent b099dbe8cd
commit b982927b4a
20 files changed
+1863 -222

No files matched your search

@@ -10,6 +10,11 @@ import {
AlertDialogTitle,
} from '@/components/ui/alert-dialog';
import { buttonVariants } from '@/components/ui/button';
import {
actionErrorMessage,
useActionFeedback,
type ActionFeedbackOptions,
} from '@/contexts/ActionFeedbackContext';
import { cn } from '@/lib/utils';
interface ConfirmDialogProps {
@@ -20,6 +25,9 @@ interface ConfirmDialogProps {
confirmText?: string;
cancelText?: string;
destructive?: boolean;
content?: ReactNode;
confirmDisabled?: boolean;
activity?: ActionFeedbackOptions<void>;
onConfirm: () => void | Promise<void>;
}
@@ -31,25 +39,57 @@ export function ConfirmDialog({
confirmText = '确认',
cancelText = '取消',
destructive = false,
content,
confirmDisabled = false,
activity,
onConfirm,
}: ConfirmDialogProps) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const { runAction } = useActionFeedback();
const handleConfirm = async () => {
setBusy(true);
setError(null);
try {
await onConfirm();
if (!activity) {
await onConfirm();
} else {
await runAction(activity, onConfirm);
}
onOpenChange(false);
} catch (caught) {
const message = actionErrorMessage(caught);
setError(message);
console.error('confirm action failed', caught);
} finally {
setBusy(false);
}
};
const handleOpenChange = (nextOpen: boolean) => {
if (busy && !nextOpen) return;
if (!nextOpen) setError(null);
onOpenChange(nextOpen);
};
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialog open={open} onOpenChange={handleOpenChange}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{title}</AlertDialogTitle>
{description && <AlertDialogDescription>{description}</AlertDialogDescription>}
{description && (
<AlertDialogDescription asChild>
<div>{description}</div>
</AlertDialogDescription>
)}
</AlertDialogHeader>
{error && (
<div role="alert" className="rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive">
{error}
</div>
)}
{content}
<AlertDialogFooter>
<AlertDialogCancel disabled={busy}>{cancelText}</AlertDialogCancel>
<AlertDialogAction
@@ -58,7 +98,7 @@ export function ConfirmDialog({
void handleConfirm();
}}
className={cn(destructive && buttonVariants({ variant: 'destructive' }))}
disabled={busy}
disabled={busy || confirmDisabled}
>
{busy ? '处理中…' : confirmText}
</AlertDialogAction>