fix(webui): make action feedback easier to notice (#6702)

* fix(webui): make action feedback easier to notice

* fix(webui): preserve undo and report confirmed action results

* refactor(webui): trim toast preview and redundant coverage

* test(webui): advance the undo window for the last topic deletion
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-18 16:10:02 +08:00
1 parent 0f45d74fec
commit 9ccf3b6214
59 files changed
+1621 -508

No files matched your search

+5 -6
View File
@@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
import { MarkdownText, preloadMarkdownText } from "@/components/MarkdownText";
import { Button } from "@/components/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { useToast } from "@/components/ui/toast";
import { useOverlayEscapeFocus } from "@/hooks/useOverlayEscapeFocus";
import type { GoalStateWsPayload } from "@/lib/types";
@@ -18,7 +19,7 @@ export function GoalIsland({ goal, cancelDisabled, onCancel }: {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const [cancelling, setCancelling] = useState(false);
const [cancelFailed, setCancelFailed] = useState(false);
const showToast = useToast();
const [scrollBody, setScrollBody] = useState<HTMLDivElement | null>(null);
const panelRef = useRef<HTMLDivElement>(null);
const escapeFocus = useOverlayEscapeFocus();
@@ -53,11 +54,10 @@ export function GoalIsland({ goal, cancelDisabled, onCancel }: {
title={cancelDisabled ? t("thread.composer.cancelGoalOffline") : undefined}
onClick={async () => {
setCancelling(true);
setCancelFailed(false);
try {
await onCancel();
} catch {
setCancelFailed(true);
showToast?.({ message: t("thread.composer.cancelGoalFailed"), tone: "error", dedupeKey: "cancel-goal" });
} finally {
setCancelling(false);
}
@@ -66,7 +66,7 @@ export function GoalIsland({ goal, cancelDisabled, onCancel }: {
useLayoutEffect(() => {
if (!scrollBody) return;
if (status === "blocked" || cancelFailed) scrollBody.scrollTop = 0;
if (status === "blocked") scrollBody.scrollTop = 0;
const measure = () => {
scrollBody.toggleAttribute("data-overflow-top", scrollBody.scrollTop > 1);
scrollBody.toggleAttribute("data-overflow-bottom", scrollBody.scrollHeight - scrollBody.clientHeight - scrollBody.scrollTop > 1);
@@ -80,7 +80,7 @@ export function GoalIsland({ goal, cancelDisabled, onCancel }: {
observer.disconnect();
scrollBody.removeEventListener("scroll", measure);
};
}, [scrollBody, status, cancelFailed]);
}, [scrollBody, status]);
return (
<div className="goal-island-position">
@@ -120,7 +120,6 @@ export function GoalIsland({ goal, cancelDisabled, onCancel }: {
</div> : null}
<div ref={setScrollBody} className="goal-island-body">
<div className="goal-island-document">
{cancelFailed ? <p role="alert" className="mb-2 text-caption text-destructive">{t("thread.composer.cancelGoalFailed")}</p> : null}
{status === "blocked" ? <div className="goal-island-blocked">
<CircleAlert className="goal-island-status-icon" strokeWidth={2.5} aria-hidden="true" />
<span className="sr-only">{t("thread.composer.goalBlocked")}</span>
@@ -87,6 +87,7 @@ export function SessionInfoPopoverView({ jobs, loading, loadFailed, now, onActio
setDetailOpen(true);
};
const handOffDetail = (next: () => void) => {
setActionError(null);
afterDetailClose.current = next;
setDetailOpen(false);
};
@@ -249,8 +250,12 @@ export function SessionInfoPopoverView({ jobs, loading, loadFailed, now, onActio
<AutomationEditDialog
job={pendingEdit}
saving={actionKey === `update:${pendingEdit?.id ?? ""}`}
error={pendingEdit ? actionError : null}
onOpenChange={(nextOpen) => {
if (!nextOpen) setPendingEdit(null);
if (!nextOpen) {
setPendingEdit(null);
setActionError(null);
}
}}
onCancel={(job) => {
setInspectedJob(job);
@@ -261,8 +266,12 @@ export function SessionInfoPopoverView({ jobs, loading, loadFailed, now, onActio
<AutomationDeleteDialog
job={pendingDelete}
deleting={actionKey === `delete:${pendingDelete?.id ?? ""}`}
error={pendingDelete ? actionError : null}
onOpenChange={(nextOpen) => {
if (!nextOpen) setPendingDelete(null);
if (!nextOpen) {
setPendingDelete(null);
setActionError(null);
}
}}
onConfirm={(job) => handleAction("delete", job)}
/>
+22 -41
View File
@@ -66,6 +66,7 @@ import {
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { useToast } from "@/components/ui/toast";
import { AttachmentCard, AttachmentTypeFace, attachmentCardActionClassName } from "@/components/AttachmentCard";
import { ComposerActionIcon, type ComposerActionState } from "@/components/thread/ComposerActionIcon";
import {
@@ -153,8 +154,6 @@ import {
const VOICE_SHORTCUT_CODE = "KeyD";
const VOICE_SHORTCUT_ARIA = "Control+Shift+D";
const VOICE_ERROR_VISIBLE_MS = 3_500;
const VOICE_ERROR_FADE_MS = 500;
type VoiceShortcutPlatform = "apple" | "chromeos" | "linux" | "other" | "windows";
function formatBytes(n: number): string {
@@ -621,6 +620,8 @@ export function ThreadComposer({
end: number;
} | null>(null);
const [inlineError, setInlineError] = useState<string | null>(null);
const [voiceSetupError, setVoiceSetupError] = useState<VoiceRecorderErrorKey | null>(null);
const showToast = useToast();
const [sendPending, setSendPending] = useState(false);
const [pathInspection, setPathInspection] = useState<{
generation: number; scope: string; range: PastedPathRange; attachment?: LocalAttachment;
@@ -713,7 +714,6 @@ export function ThreadComposer({
useEffect(() => {
if (queueSnapshot.error) setInlineError(queueSnapshot.error);
}, [queueSnapshot.error]);
const [voiceErrorFading, setVoiceErrorFading] = useState(false);
const [slashMenuDismissed, setSlashMenuDismissed] = useState(false);
const [selectedCommandIndex, setSelectedCommandIndex] = useState(0);
const [cliAppMenuDismissed, setCliAppMenuDismissed] = useState(false);
@@ -756,7 +756,6 @@ export function ThreadComposer({
const chipRefs = useRef(new Map<string, HTMLButtonElement>());
const previousPendingQueueKeyRef = useRef(pendingQueueKey);
const voiceShortcutDownRef = useRef(false);
const voiceErrorFadeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const isHero = variant === "hero";
const voiceShortcutLabel = useMemo(getVoiceShortcutLabel, []);
const projectPickerAvailable =
@@ -818,6 +817,10 @@ export function ThreadComposer({
const { rejected } = enqueue(files);
if (rejected.length > 0) {
const { reason, file } = rejected[0];
if (reason === "empty_file" || reason === "unsupported_type") {
showToast?.({ message: formatRejection(reason), tone: "error", dedupeKey: `attachment:${reason}` });
return;
}
setInlineError(reason === "too_large"
? formatUploadTooLarge(file.size, acceptedAttachmentKind(file) === "video" ? MAX_VIDEO_BYTES : maxFileBytes)
: formatRejection(reason));
@@ -825,7 +828,7 @@ export function ThreadComposer({
setInlineError(null);
}
},
[enqueue, formatRejection, formatUploadTooLarge, interactionDisabled, maxFileBytes],
[enqueue, formatRejection, formatUploadTooLarge, interactionDisabled, maxFileBytes, showToast],
);
const {
@@ -1391,6 +1394,7 @@ export function ThreadComposer({
previousPendingQueueKeyRef.current = pendingQueueKey;
setValue("");
setInlineError(null);
setVoiceSetupError(null);
setSlashMenuDismissed(false);
setCliAppMenuDismissed(false);
setCursorPosition(0);
@@ -1407,43 +1411,27 @@ export function ThreadComposer({
});
setSlashMenuDismissed(false);
setCliAppMenuDismissed(false);
setInlineError(null);
focusTextarea();
}, [focusTextarea]);
const clearVoiceErrorTimers = useCallback(() => {
if (voiceErrorFadeTimerRef.current !== null) clearTimeout(voiceErrorFadeTimerRef.current);
voiceErrorFadeTimerRef.current = null;
}, []);
const clearInlineError = useCallback(() => {
clearVoiceErrorTimers();
setVoiceErrorFading(false);
setInlineError(null);
}, [clearVoiceErrorTimers]);
const clearVoiceSetupError = useCallback(() => setVoiceSetupError(null), []);
const setVoiceError = useCallback((key: VoiceRecorderErrorKey) => {
clearVoiceErrorTimers();
setVoiceErrorFading(false);
setInlineError(t(`thread.composer.voiceErrors.${key}`));
voiceErrorFadeTimerRef.current = setTimeout(() => {
setVoiceErrorFading(true);
voiceErrorFadeTimerRef.current = setTimeout(() => {
setInlineError(null);
setVoiceErrorFading(false);
voiceErrorFadeTimerRef.current = null;
}, VOICE_ERROR_FADE_MS);
}, VOICE_ERROR_VISIBLE_MS);
}, [clearVoiceErrorTimers, t]);
// Setup blockers carry instructions users may need to keep in view while fixing them.
if (key === "insecureContext" || key === "permission" || key === "notConfigured") {
setVoiceSetupError(key);
return;
}
showToast?.({ message: t(`thread.composer.voiceErrors.${key}`), tone: "error", dedupeKey: "voice-input" });
}, [showToast, t]);
const voiceRecorder = useVoiceRecorder({
disabled: interactionDisabled,
onClearError: clearInlineError,
onClearError: clearVoiceSetupError,
onError: setVoiceError,
onTranscript: appendTranscription,
onTranscribeAudio,
wantsWav: transcriptionProvider === "xiaomi_mimo",
});
useEffect(() => () => clearVoiceErrorTimers(), [clearVoiceErrorTimers]);
useEffect(() => {
if (!onTranscribeAudio) return;
@@ -1940,7 +1928,7 @@ export function ThreadComposer({
: showStopButton ? "stop" : requiresModelSetup ? "setup" : canSend || !isStreaming ? "send" : "busy";
const relaxedHeroInput = isHero && images.length === 0 && !isStreaming;
const compactIdle = compactWhenIdle && !compactControls && !isHero && !composerFocused
&& value.length === 0 && images.length === 0 && !inlineError
&& value.length === 0 && images.length === 0 && !inlineError && !(onTranscribeAudio && voiceSetupError)
&& !normalizedQuotedContext && !queuedPrompt
&& !isDragging && !sessionDragPreview && !voiceRecorder.isRecording && !showProjectPicker;
useLayoutEffect(() => {
@@ -2229,16 +2217,9 @@ export function ThreadComposer({
)}
/>
</div>
{inlineError ? (
<div
role="alert"
className={cn(
"mx-3 mb-1 max-h-24 overflow-hidden rounded-md border border-destructive/40 bg-destructive/8 px-2.5 py-1",
"text-[11.5px] font-medium text-destructive transition-[max-height,margin,padding,opacity] [transition-duration:220ms] ease-out motion-reduce:transition-none",
voiceErrorFading && "mb-0 max-h-0 border-transparent py-0 opacity-0",
)}
>
{inlineError}
{inlineError || (onTranscribeAudio && voiceSetupError) ? (
<div role="alert" className="mx-3 mb-1 break-words rounded-md border border-destructive/40 bg-destructive/8 px-2.5 py-1 text-[11.5px] font-medium text-destructive">
{inlineError ?? t(`thread.composer.voiceErrors.${voiceSetupError}`)}
</div>
) : null}
<div