refactor(webui): prune unused legacy components

This commit is contained in:
Xubin Ren
2026-05-24 19:43:20 +08:00
parent 704ac558f6
commit 6ea7a6a2ac
7 changed files with 0 additions and 369 deletions
-124
View File
@@ -1,124 +0,0 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { ArrowUp } from "lucide-react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
interface ComposerProps {
onSend: (content: string) => void;
disabled?: boolean;
placeholder?: string;
/** Visually collapse the outer padding when embedded inside a welcome screen. */
compact?: boolean;
}
/**
* Rounded, shadowed composer with an embedded send button — modeled after the
* agent-chat-ui input: a single surface that looks like one interactive unit
* rather than a textarea + button pair.
*/
export function Composer({
onSend,
disabled,
placeholder = "Type your message…",
compact = false,
}: ComposerProps) {
const [value, setValue] = useState("");
const textareaRef = useRef<HTMLTextAreaElement>(null);
// Autofocus on mount — coming back to a chat, switching sessions, or
// opening the welcome screen should always land the caret in the box.
useEffect(() => {
if (disabled) return;
const el = textareaRef.current;
if (!el) return;
// Defer so layout settles first (important during enter animations).
const id = requestAnimationFrame(() => el.focus());
return () => cancelAnimationFrame(id);
}, [disabled]);
const submit = useCallback(() => {
const trimmed = value.trim();
if (!trimmed || disabled) return;
onSend(trimmed);
setValue("");
requestAnimationFrame(() => {
const el = textareaRef.current;
if (el) {
el.style.height = "auto";
el.focus();
}
});
}, [disabled, onSend, value]);
const onKeyDown: React.KeyboardEventHandler<HTMLTextAreaElement> = (e) => {
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
e.preventDefault();
submit();
}
};
const onInput: React.FormEventHandler<HTMLTextAreaElement> = (e) => {
const el = e.currentTarget;
el.style.height = "auto";
el.style.height = `${Math.min(el.scrollHeight, 260)}px`;
};
return (
<form
onSubmit={(e) => {
e.preventDefault();
submit();
}}
className={cn(
"w-full",
compact ? "px-0" : "bg-background/95 px-4 pb-4 pt-2 backdrop-blur",
)}
>
<div
className={cn(
"relative mx-auto flex w-full max-w-[64rem] flex-col overflow-hidden rounded-3xl",
"border bg-muted/60 shadow-sm transition-all duration-200",
"focus-within:bg-muted focus-within:shadow-md focus-within:ring-1 focus-within:ring-foreground/10",
disabled && "opacity-60",
)}
>
<textarea
ref={textareaRef}
value={value}
onChange={(e) => setValue(e.target.value)}
onInput={onInput}
onKeyDown={onKeyDown}
rows={1}
placeholder={placeholder}
disabled={disabled}
aria-label="Message input"
className={cn(
"min-h-[56px] w-full resize-none bg-transparent px-5 pt-4 pb-2 text-sm",
"placeholder:text-muted-foreground",
"focus:outline-none focus-visible:outline-none",
"disabled:cursor-not-allowed",
)}
/>
<div className="flex items-center justify-between gap-2 px-3 pb-2">
<span className="hidden select-none text-[11px] text-muted-foreground/70 sm:inline">
Enter to send · Shift+Enter for newline
</span>
<span className="sm:hidden" aria-hidden />
<Button
type="submit"
size="icon"
disabled={disabled || !value.trim()}
aria-label="Send message"
className={cn(
"h-9 w-9 rounded-full shadow-sm transition-transform",
value.trim() && !disabled && "hover:scale-[1.03] active:scale-95",
)}
>
<ArrowUp className="h-4 w-4" />
</Button>
</div>
</div>
</form>
);
}
-26
View File
@@ -1,26 +0,0 @@
import { MessageSquarePlus } from "lucide-react";
import { Button } from "@/components/ui/button";
export function EmptyState({
onNewChat,
}: {
onNewChat: () => void;
}) {
return (
<div className="flex h-full flex-col items-center justify-center gap-4 text-center">
<MessageSquarePlus
className="h-10 w-10 text-muted-foreground"
aria-hidden
/>
<div className="space-y-1">
<p className="text-lg font-medium">No chats yet</p>
<p className="max-w-sm text-sm text-muted-foreground">
Start a conversation your sessions are stored locally on the nanobot
workspace and stay available across reloads.
</p>
</div>
<Button onClick={onNewChat}>New chat</Button>
</div>
);
}
-109
View File
@@ -1,109 +0,0 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { ArrowDown } from "lucide-react";
import { MessageBubble } from "@/components/MessageBubble";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import type { UIMessage } from "@/lib/types";
interface MessageListProps {
messages: UIMessage[];
isStreaming: boolean;
}
const NEAR_BOTTOM_PX = 48;
/**
* Scrollable message log. Auto-sticks to the bottom as new content arrives,
* but only when the user was already at the bottom — preserving scroll
* position when they've scrolled up to read earlier turns. A floating
* "scroll to bottom" button appears whenever we're detached from the bottom.
*/
export function MessageList({ messages, isStreaming }: MessageListProps) {
const scrollRef = useRef<HTMLDivElement>(null);
const [atBottom, setAtBottom] = useState(true);
const scrollToBottom = useCallback((smooth = false) => {
const el = scrollRef.current;
if (!el) return;
el.scrollTo({
top: el.scrollHeight,
behavior: smooth ? "smooth" : "auto",
});
}, []);
// Keep the viewport pinned to the bottom as long as the user hasn't
// scrolled up. During streaming we do instant jumps (smooth scrolling each
// token fights the incoming animations); on settled updates we animate.
useEffect(() => {
if (!atBottom) return;
scrollToBottom(!isStreaming);
}, [messages, isStreaming, atBottom, scrollToBottom]);
useEffect(() => {
const el = scrollRef.current;
if (!el) return;
const onScroll = () => {
const distance = el.scrollHeight - el.scrollTop - el.clientHeight;
setAtBottom(distance < NEAR_BOTTOM_PX);
};
el.addEventListener("scroll", onScroll, { passive: true });
return () => el.removeEventListener("scroll", onScroll);
}, []);
if (messages.length === 0) {
return (
<div className="flex h-full items-center justify-center text-sm text-muted-foreground">
Say hi to get started.
</div>
);
}
return (
<div className="relative flex min-h-0 flex-1 overflow-hidden">
<div
ref={scrollRef}
className={cn(
"h-full overflow-y-auto scroll-smooth",
"[&::-webkit-scrollbar]:w-1.5",
"[&::-webkit-scrollbar-thumb]:rounded-full",
"[&::-webkit-scrollbar-thumb]:bg-muted-foreground/30",
"[&::-webkit-scrollbar-track]:bg-transparent",
)}
>
<div className="mx-auto flex w-full max-w-[64rem] flex-col gap-6 px-4 pt-4 pb-8">
{messages.map((m) => (
<MessageBubble key={m.id} message={m} />
))}
</div>
</div>
{/* Top fade so messages slide under the header gracefully. */}
<div
aria-hidden
className="pointer-events-none absolute inset-x-0 top-0 h-6 bg-gradient-to-b from-background to-transparent"
/>
{/* Bottom fade so messages fade out behind the composer. */}
<div
aria-hidden
className="pointer-events-none absolute inset-x-0 bottom-0 h-8 bg-gradient-to-t from-background to-transparent"
/>
{!atBottom && (
<Button
variant="outline"
size="icon"
onClick={() => scrollToBottom(true)}
className={cn(
"absolute bottom-2 left-1/2 h-8 w-8 -translate-x-1/2 rounded-full shadow-md",
"bg-background/90 backdrop-blur",
"animate-in fade-in-0 zoom-in-95",
)}
aria-label="Scroll to bottom"
>
<ArrowDown className="h-4 w-4" />
</Button>
)}
</div>
);
}
-48
View File
@@ -1,48 +0,0 @@
import * as React from "react";
import * as AvatarPrimitive from "@radix-ui/react-avatar";
import { cn } from "@/lib/utils";
const Avatar = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Root
ref={ref}
className={cn(
"relative flex h-9 w-9 shrink-0 overflow-hidden rounded-full",
className,
)}
{...props}
/>
));
Avatar.displayName = AvatarPrimitive.Root.displayName;
const AvatarImage = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Image>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Image
ref={ref}
className={cn("aspect-square h-full w-full", className)}
{...props}
/>
));
AvatarImage.displayName = AvatarPrimitive.Image.displayName;
const AvatarFallback = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted text-xs font-medium",
className,
)}
{...props}
/>
));
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
export { Avatar, AvatarFallback, AvatarImage };
-46
View File
@@ -1,46 +0,0 @@
import * as React from "react";
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import { cn } from "@/lib/utils";
const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ScrollAreaPrimitive.Root
ref={ref}
className={cn("relative overflow-hidden", className)}
{...props}
>
<ScrollAreaPrimitive.Viewport className="h-full w-full min-w-0 rounded-[inherit]">
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
));
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={cn(
"flex touch-none select-none transition-colors",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
className,
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
));
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
export { ScrollArea, ScrollBar };