feat(webui): refresh the empty chat welcome (#6650)
* feat(webui): refresh the empty chat welcome * fix(webui): keep empty chat accessible in split panes * chore(webui): remove unused fixture test id
This commit is contained in:
1 parent
90d69e7a11
commit
6a24b17629
26 files changed
+283
-205
No files matched your search
@@ -22,6 +22,7 @@ import { latestSubagentInputKey } from "@/lib/subagent-tasks";
|
||||
import { SessionInfoPopover } from "@/components/thread/SessionInfoPopover";
|
||||
import type { ComposerDraft, ComposerDraftStore } from "@/lib/composer-draft";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import { ThreadWelcomeMark } from "@/components/thread/ThreadWelcomeMark";
|
||||
import {
|
||||
ComposerUsagePopover,
|
||||
type ComposerContextUsage,
|
||||
@@ -260,89 +261,6 @@ interface ThreadShellProps {
|
||||
skills?: SkillSummary[];
|
||||
}
|
||||
|
||||
const HERO_GREETING_KEYS = [
|
||||
"thread.empty.greetings.workOn",
|
||||
"thread.empty.greetings.start",
|
||||
"thread.empty.greetings.build",
|
||||
"thread.empty.greetings.tackle",
|
||||
] as const;
|
||||
|
||||
function HeroGreeting({ text }: { text: string }) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const headingRef = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const container = containerRef.current;
|
||||
const heading = headingRef.current;
|
||||
if (!container || !heading) return;
|
||||
|
||||
const fitToWidth = () => {
|
||||
heading.style.removeProperty("font-size");
|
||||
const availableWidth = container.clientWidth;
|
||||
if (availableWidth <= 0) return;
|
||||
|
||||
const naturalWidth = heading.scrollWidth;
|
||||
const maximumFontSize = Number.parseFloat(window.getComputedStyle(heading).fontSize);
|
||||
if (
|
||||
naturalWidth <= availableWidth
|
||||
|| !Number.isFinite(maximumFontSize)
|
||||
|| maximumFontSize <= 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fittedFontSize = Math.max(
|
||||
12,
|
||||
Math.floor(maximumFontSize * ((availableWidth - 2) / naturalWidth) * 100) / 100,
|
||||
);
|
||||
heading.style.fontSize = `${fittedFontSize}px`;
|
||||
};
|
||||
|
||||
fitToWidth();
|
||||
|
||||
let lastObservedWidth = container.clientWidth;
|
||||
const resizeObserver = typeof ResizeObserver === "undefined"
|
||||
? null
|
||||
: new ResizeObserver(([entry]) => {
|
||||
const nextWidth = entry?.contentRect.width ?? container.clientWidth;
|
||||
if (nextWidth === lastObservedWidth) return;
|
||||
lastObservedWidth = nextWidth;
|
||||
fitToWidth();
|
||||
});
|
||||
resizeObserver?.observe(container);
|
||||
window.addEventListener("resize", fitToWidth);
|
||||
|
||||
let cancelled = false;
|
||||
void document.fonts?.ready.then(() => {
|
||||
if (!cancelled) fitToWidth();
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
resizeObserver?.disconnect();
|
||||
window.removeEventListener("resize", fitToWidth);
|
||||
};
|
||||
}, [text]);
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="min-w-0 w-full max-w-[44rem]">
|
||||
<h1
|
||||
ref={headingRef}
|
||||
data-testid="hero-greeting"
|
||||
data-theme-ink
|
||||
className="select-none whitespace-nowrap text-[34px] font-normal leading-[1.08] tracking-normal text-foreground sm:text-[48px] sm:leading-tight"
|
||||
>
|
||||
{text}
|
||||
</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function randomHeroGreetingKey(): (typeof HERO_GREETING_KEYS)[number] {
|
||||
const index = Math.floor(Math.random() * HERO_GREETING_KEYS.length);
|
||||
return HERO_GREETING_KEYS[index] ?? HERO_GREETING_KEYS[0];
|
||||
}
|
||||
|
||||
interface PendingFirstMessage {
|
||||
finish?: (accepted: boolean) => void;
|
||||
content: string;
|
||||
@@ -550,7 +468,6 @@ export function ThreadShell({
|
||||
dismissed: boolean;
|
||||
} | null>(null);
|
||||
const sandboxNotice = useSandboxNotice(client, chatId, webuiCapabilities.includes("webui.sandbox-settings.v1"));
|
||||
const [heroGreetingKey, setHeroGreetingKey] = useState(randomHeroGreetingKey);
|
||||
const [submittedViewportTurnId, setSubmittedViewportTurnId] = useState<string | null>(null);
|
||||
const { state: previewState, openFile, resolveFile, selectTab, closeTab, close: closePreview, setWidth: setFilePreviewWidth } =
|
||||
useFilePreviewState(previewSessionKey, filePreviewStore);
|
||||
@@ -853,7 +770,6 @@ export function ThreadShell({
|
||||
const composerVariant = showHeroComposer ? emptyComposerVariant : "thread";
|
||||
// Only unpersisted drafts can choose a project; history pages do not own this state.
|
||||
const projectLocked = !!session && session.projectLocked !== false;
|
||||
const wasShowingHeroComposerRef = useRef(showHeroComposer);
|
||||
const sessionModelPreset = session?.modelPreset?.trim() || null;
|
||||
const [localModelPreset, setLocalModelPreset] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
@@ -923,13 +839,6 @@ export function ThreadShell({
|
||||
const modelBadgeLabel = modelBadge.needsSetup
|
||||
? t("thread.composer.chooseAI", { defaultValue: "Choose your AI" })
|
||||
: modelBadge.label;
|
||||
useEffect(() => {
|
||||
if (showHeroComposer && !wasShowingHeroComposerRef.current) {
|
||||
setHeroGreetingKey(randomHeroGreetingKey());
|
||||
}
|
||||
wasShowingHeroComposerRef.current = showHeroComposer;
|
||||
}, [showHeroComposer]);
|
||||
|
||||
const withWorkspaceScope = useCallback(
|
||||
(options?: SendOptions): SendOptions | undefined => {
|
||||
if (!workspaceScope) return options;
|
||||
@@ -1494,9 +1403,10 @@ export function ThreadShell({
|
||||
const emptyState = initialHistoryLoading ? (
|
||||
<ThreadLoadingSkeleton />
|
||||
) : (
|
||||
<div className="flex w-full flex-col items-center text-center animate-in fade-in-0 slide-in-from-bottom-2 [animation-duration:220ms] motion-reduce:animate-none">
|
||||
<HeroGreeting text={t(heroGreetingKey)} />
|
||||
</div>
|
||||
<>
|
||||
<h1 className="sr-only">{session ? title : t(temporary || temporaryChatEnabled ? "temporaryChat.title" : "sidebar.newChat")}</h1>
|
||||
<ThreadWelcomeMark />
|
||||
</>
|
||||
);
|
||||
const sessionInfoAction = historyKey ? (
|
||||
<SessionInfoPopover client={client} sessionKey={historyKey} token={token} />
|
||||
|
||||
@@ -1330,7 +1330,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
ref={emptyStateRef}
|
||||
data-testid="thread-empty-region"
|
||||
className={cn(
|
||||
"row-start-1 min-h-0 min-w-0 w-full",
|
||||
"relative row-start-1 min-h-0 min-w-0 w-full [container-type:inline-size]",
|
||||
initialLoading
|
||||
? "overflow-hidden"
|
||||
: cn("flex items-center justify-center", hasComposer && "sm:items-end sm:pb-8"),
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import "./thread-welcome-mark.css";
|
||||
|
||||
export function ThreadWelcomeMark() {
|
||||
const markRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const mark = markRef.current;
|
||||
if (!mark) return;
|
||||
|
||||
const motionPreference = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
let currentX = 0;
|
||||
let currentY = 0;
|
||||
let targetX = 0;
|
||||
let targetY = 0;
|
||||
let frame = 0;
|
||||
let lastFrame: number | null = null;
|
||||
let initialized = false;
|
||||
|
||||
const renderPosition = () => {
|
||||
mark.style.setProperty("--mark-x", `${currentX}px`);
|
||||
mark.style.setProperty("--mark-y", `${currentY}px`);
|
||||
};
|
||||
|
||||
const followPointer = (timestamp: number) => {
|
||||
const elapsed = lastFrame === null ? 0 : timestamp - lastFrame;
|
||||
lastFrame = timestamp;
|
||||
const step = 1 - Math.exp(-elapsed / 165);
|
||||
currentX += (targetX - currentX) * step;
|
||||
currentY += (targetY - currentY) * step;
|
||||
if (Math.hypot(targetX - currentX, targetY - currentY) < 0.3) {
|
||||
currentX = targetX;
|
||||
currentY = targetY;
|
||||
frame = 0;
|
||||
lastFrame = null;
|
||||
} else {
|
||||
frame = window.requestAnimationFrame(followPointer);
|
||||
}
|
||||
renderPosition();
|
||||
};
|
||||
|
||||
const onPointerMove = (event: PointerEvent) => {
|
||||
if (event.pointerType === "touch") return;
|
||||
const bounds = mark.getBoundingClientRect();
|
||||
targetX = event.clientX - bounds.left;
|
||||
targetY = event.clientY - bounds.top;
|
||||
mark.style.setProperty("--mark-active", "1");
|
||||
if (!initialized || motionPreference.matches) {
|
||||
if (frame) window.cancelAnimationFrame(frame);
|
||||
frame = 0;
|
||||
lastFrame = null;
|
||||
currentX = targetX;
|
||||
currentY = targetY;
|
||||
initialized = true;
|
||||
renderPosition();
|
||||
} else if (!frame) {
|
||||
frame = window.requestAnimationFrame(followPointer);
|
||||
}
|
||||
};
|
||||
|
||||
const hideFocus = () => {
|
||||
mark.style.setProperty("--mark-active", "0");
|
||||
if (frame) window.cancelAnimationFrame(frame);
|
||||
frame = 0;
|
||||
lastFrame = null;
|
||||
initialized = false;
|
||||
};
|
||||
const onPointerOut = (event: PointerEvent) => {
|
||||
if (!event.relatedTarget) hideFocus();
|
||||
};
|
||||
|
||||
window.addEventListener("pointermove", onPointerMove);
|
||||
window.addEventListener("pointerout", onPointerOut);
|
||||
window.addEventListener("blur", hideFocus);
|
||||
return () => {
|
||||
window.removeEventListener("pointermove", onPointerMove);
|
||||
window.removeEventListener("pointerout", onPointerOut);
|
||||
window.removeEventListener("blur", hideFocus);
|
||||
if (frame) window.cancelAnimationFrame(frame);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div ref={markRef} aria-hidden="true" data-testid="thread-welcome-mark" className="thread-welcome-mark">
|
||||
<div className="thread-welcome-mark__fill" />
|
||||
<div className="thread-welcome-mark__focus" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
.thread-welcome-mark {
|
||||
position: absolute;
|
||||
bottom: -3rem;
|
||||
left: 50%;
|
||||
/* 94.76cqw is the height of the 783:742 mark at its container's width. */
|
||||
height: min(19.9rem, calc(100% + 3rem), 66.3vw, 94.76cqw);
|
||||
aspect-ratio: 783 / 742;
|
||||
pointer-events: none;
|
||||
transform: translateX(-50%);
|
||||
mask-image: linear-gradient(to bottom, #000 0%, rgb(0 0 0 / 0.8) 32%, rgb(0 0 0 / 0.28) 70%, transparent 100%);
|
||||
-webkit-mask-image: linear-gradient(to bottom, #000 0%, rgb(0 0 0 / 0.8) 32%, rgb(0 0 0 / 0.28) 70%, transparent 100%);
|
||||
}
|
||||
|
||||
.thread-welcome-mark__fill,
|
||||
.thread-welcome-mark__focus {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
|
||||
.thread-welcome-mark__fill {
|
||||
background: url('/brand/nanobot_mark.svg') center / calc(100% * 759 / 783) auto no-repeat;
|
||||
filter: grayscale(1);
|
||||
opacity: 0.06;
|
||||
}
|
||||
|
||||
.thread-welcome-mark__focus {
|
||||
mask: url('/brand/nanobot_mark_outline.svg') center / contain no-repeat;
|
||||
-webkit-mask: url('/brand/nanobot_mark_outline.svg') center / contain no-repeat;
|
||||
background: radial-gradient(circle 12rem at var(--mark-x, -200px) var(--mark-y, -200px), hsl(0 0% 25% / 0.06), hsl(0 0% 25% / 0.02) 50%, transparent 100%);
|
||||
opacity: var(--mark-active, 0);
|
||||
transition: opacity 600ms ease;
|
||||
}
|
||||
|
||||
.dark .thread-welcome-mark__fill { opacity: 0.05; }
|
||||
.dark .thread-welcome-mark__focus {
|
||||
background: radial-gradient(circle 12rem at var(--mark-x, -200px) var(--mark-y, -200px), hsl(0 0% 100% / 0.05), hsl(0 0% 100% / 0.016) 50%, transparent 100%);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.thread-welcome-mark__focus { transition: none; }
|
||||
}
|
||||
Reference in new issue
Block a user