ui: ScrollArea, Skeleton loading, apes can't set message type

- ScrollArea for messages + sidebar (themed scrollbar)
- Skeleton loading state on channel switch (3 placeholder rows)
- Apes only see ">" prefix and "enter to send" — no type cycling
- Agents get full type selector (Tab/Ctrl+1-5)
- Better empty state text

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 21:10:39 +02:00
parent 6ba6719932
commit 3c33215b29
3 changed files with 71 additions and 42 deletions

View File

@@ -6,6 +6,8 @@ import { ChannelSidebar } from "@/components/ChannelSidebar";
import { MessageItem } from "@/components/MessageItem"; import { MessageItem } from "@/components/MessageItem";
import { ComposeBox } from "@/components/ComposeBox"; import { ComposeBox } from "@/components/ComposeBox";
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"; import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Skeleton } from "@/components/ui/skeleton";
import { useChannelSocket } from "@/hooks/useChannelSocket"; import { useChannelSocket } from "@/hooks/useChannelSocket";
function GatePage() { function GatePage() {
@@ -40,6 +42,7 @@ export default function App() {
const [channels, setChannels] = useState<Channel[]>([]); const [channels, setChannels] = useState<Channel[]>([]);
const [activeChannelId, setActiveChannelId] = useState<string | null>(null); const [activeChannelId, setActiveChannelId] = useState<string | null>(null);
const [messages, setMessages] = useState<Message[]>([]); const [messages, setMessages] = useState<Message[]>([]);
const [loading, setLoading] = useState(false);
const [replyTo, setReplyTo] = useState<string | null>(null); const [replyTo, setReplyTo] = useState<string | null>(null);
const [sheetOpen, setSheetOpen] = useState(false); const [sheetOpen, setSheetOpen] = useState(false);
const scrollRef = useRef<HTMLDivElement>(null); const scrollRef = useRef<HTMLDivElement>(null);
@@ -57,6 +60,7 @@ export default function App() {
const loadMessages = useCallback(async () => { const loadMessages = useCallback(async () => {
const channelId = activeChannelRef.current; const channelId = activeChannelRef.current;
if (!channelId) return; if (!channelId) return;
setLoading(true);
try { try {
const msgs = await getMessages(channelId); const msgs = await getMessages(channelId);
if (activeChannelRef.current === channelId) { if (activeChannelRef.current === channelId) {
@@ -64,6 +68,8 @@ export default function App() {
} }
} catch { } catch {
// Silently ignore fetch errors // Silently ignore fetch errors
} finally {
setLoading(false);
} }
}, []); }, []);
@@ -149,21 +155,34 @@ export default function App() {
)} )}
</div> </div>
<div ref={scrollRef} className="flex-1 overflow-y-auto"> <ScrollArea ref={scrollRef} className="flex-1">
{messages.length === 0 && activeChannelId && ( {loading && messages.length === 0 ? (
<div className="flex items-center justify-center h-full text-muted-foreground text-xs"> <div className="p-5 space-y-4">
no messages yet {[1, 2, 3].map((i) => (
<div key={i} className="flex items-start gap-3">
<Skeleton className="h-6 w-6 rounded-none" />
<div className="flex-1 space-y-2">
<Skeleton className="h-3 w-24 rounded-none" />
<Skeleton className="h-3 w-full rounded-none" />
</div> </div>
)} </div>
{messages.map((msg) => ( ))}
</div>
) : messages.length === 0 && activeChannelId ? (
<div className="flex items-center justify-center h-full text-muted-foreground text-xs font-mono py-20">
no messages yet start typing below
</div>
) : (
messages.map((msg) => (
<MessageItem <MessageItem
key={msg.id} key={msg.id}
message={msg} message={msg}
replyTarget={msg.reply_to ? messagesById.get(msg.reply_to) : undefined} replyTarget={msg.reply_to ? messagesById.get(msg.reply_to) : undefined}
onReply={setReplyTo} onReply={setReplyTo}
/> />
))} ))
</div> )}
</ScrollArea>
{activeChannelId && ( {activeChannelId && (
<ComposeBox <ComposeBox

View File

@@ -1,6 +1,7 @@
import { useState } from "react"; import { useState } from "react";
import type { Channel } from "@/types/Channel"; import type { Channel } from "@/types/Channel";
import { createChannel, getCurrentUsername } from "@/api"; import { createChannel, getCurrentUsername } from "@/api";
import { ScrollArea } from "@/components/ui/scroll-area";
interface Props { interface Props {
channels: Channel[]; channels: Channel[];
@@ -48,7 +49,7 @@ export function ChannelSidebar({
</div> </div>
{/* Channel list */} {/* Channel list */}
<div className="flex-1 overflow-y-auto"> <ScrollArea className="flex-1">
<div className="px-3 pt-3 pb-1 font-sans text-[10px] font-bold text-muted-foreground uppercase tracking-[0.2em]"> <div className="px-3 pt-3 pb-1 font-sans text-[10px] font-bold text-muted-foreground uppercase tracking-[0.2em]">
Channels Channels
</div> </div>
@@ -67,7 +68,7 @@ export function ChannelSidebar({
{ch.name} {ch.name}
</button> </button>
))} ))}
</div> </ScrollArea>
{/* User strip */} {/* User strip */}
<div className="px-3 py-2 border-t-2 border-border font-mono text-[11px]"> <div className="px-3 py-2 border-t-2 border-border font-mono text-[11px]">

View File

@@ -1,7 +1,7 @@
import { useState, useRef, useEffect, useCallback } from "react"; import { useState, useRef, useEffect, useCallback } from "react";
import type { MessageType } from "@/types/MessageType"; import type { MessageType } from "@/types/MessageType";
import type { User } from "@/types/User"; import type { User } from "@/types/User";
import { postMessage, getUsers } from "@/api"; import { postMessage, getUsers, getCurrentUsername } from "@/api";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
interface Props { interface Props {
@@ -34,6 +34,9 @@ export function ComposeBox({
const [mentionQuery, setMentionQuery] = useState(""); const [mentionQuery, setMentionQuery] = useState("");
const [mentionIdx, setMentionIdx] = useState(0); const [mentionIdx, setMentionIdx] = useState(0);
const inputRef = useRef<HTMLTextAreaElement>(null); const inputRef = useRef<HTMLTextAreaElement>(null);
// Apes only send text — type selector is for agents
const currentUser = users.find((u) => u.username === getCurrentUsername());
const isAgent = currentUser?.role === "agent";
const meta = TYPE_META[msgType]; const meta = TYPE_META[msgType];
// Load users for mention autocomplete // Load users for mention autocomplete
@@ -194,6 +197,7 @@ export function ComposeBox({
e.preventDefault(); e.preventDefault();
handleSend(); handleSend();
} }
if (isAgent) {
if (e.key === "Tab" && !e.shiftKey) { if (e.key === "Tab" && !e.shiftKey) {
e.preventDefault(); e.preventDefault();
cycleType(1); cycleType(1);
@@ -207,6 +211,7 @@ export function ComposeBox({
const types: MessageType[] = ["text", "code", "result", "error", "plan"]; const types: MessageType[] = ["text", "code", "result", "error", "plan"];
setMsgType(types[parseInt(e.key) - 1]); setMsgType(types[parseInt(e.key) - 1]);
} }
}
}} }}
placeholder="message" placeholder="message"
disabled={sending} disabled={sending}
@@ -217,8 +222,9 @@ export function ComposeBox({
)} )}
/> />
{/* Bottom bar — prefix + type indicator */} {/* Bottom bar */}
<div className="flex items-center justify-between mt-3 pt-2"> <div className="flex items-center justify-between mt-3 pt-2">
{isAgent ? (
<button <button
type="button" type="button"
onClick={() => cycleType(1)} onClick={() => cycleType(1)}
@@ -230,13 +236,16 @@ export function ComposeBox({
> >
{meta.prefix} {meta.prefix}
</button> </button>
) : (
<span className="font-mono text-xs text-muted-foreground/30">&gt;</span>
)}
<span className={cn( <span className={cn(
"text-[9px] font-mono uppercase tracking-[0.2em] transition-opacity", "text-[9px] font-mono uppercase tracking-[0.2em] transition-opacity",
meta.color, isAgent ? meta.color : "text-muted-foreground",
content ? "opacity-60" : "opacity-25", content ? "opacity-60" : "opacity-25",
)}> )}>
{msgType} · enter to send {isAgent ? `${msgType} · ` : ""}enter to send
</span> </span>
</div> </div>
</div> </div>