xonecas.io
53129
Pa

PAT / commit 2210637

feat: make it actually look nice, no more programmer ui

xonecas2025-12-17 2210637e58216c41d596c14662512ede7e1a6000 parent e5cb04d

12 files changed

app/highlight-theme.css+28−24
@@ -1,4 +1,4 @@
1-/* Custom highlight.js theme using Tailwind colors (neutral, green, orange, indigo) */
1+/* Custom highlight.js theme using grayscale colors */
22
33 /* Reset code block inheritance */
44 .prose pre,
@@ -14,7 +14,7 @@
1414
1515 /* Light mode - code blocks only */
1616 .prose pre {
17- background: #f5f5f4; /* neutral-100 */
17+ background: #e7e5e4; /* neutral-200 */
1818 padding: 0.5rem;
1919 }
2020
@@ -42,7 +42,7 @@ pre .hljs,
4242 .hljs-keyword,
4343 .hljs-selector-tag,
4444 .hljs-subst {
45- color: #166534; /* green-800 */
45+ color: #1c1917; /* neutral-900 */
4646 font-weight: 600;
4747 }
4848
@@ -56,14 +56,14 @@ pre .hljs,
5656 .hljs-variable,
5757 .hljs-template-variable,
5858 .hljs-tag .hljs-attr {
59- color: #ea580c; /* orange-600 */
59+ color: #57534e; /* neutral-600 */
6060 }
6161
6262 .prose .hljs-string,
6363 .prose .hljs-doctag,
6464 .hljs-string,
6565 .hljs-doctag {
66- color: #c2410c; /* orange-700 */
66+ color: #44403c; /* neutral-700 */
6767 }
6868
6969 .prose .hljs-title,
@@ -72,7 +72,7 @@ pre .hljs,
7272 .hljs-title,
7373 .hljs-section,
7474 .hljs-selector-id {
75- color: #4f46e5; /* indigo-600 */
75+ color: #292524; /* neutral-800 */
7676 font-weight: 600;
7777 }
7878
@@ -80,7 +80,8 @@ pre .hljs,
8080 .prose .hljs-class .hljs-title,
8181 .hljs-type,
8282 .hljs-class .hljs-title {
83- color: #6366f1; /* indigo-500 */
83+ color: #292524; /* neutral-800 */
84+ font-weight: 500;
8485 }
8586
8687 .prose .hljs-tag,
@@ -89,7 +90,7 @@ pre .hljs,
8990 .hljs-tag,
9091 .hljs-name,
9192 .hljs-attribute {
92- color: #166534; /* green-800 */
93+ color: #57534e; /* neutral-600 */
9394 font-weight: normal;
9495 }
9596
@@ -97,21 +98,22 @@ pre .hljs,
9798 .prose .hljs-link,
9899 .hljs-regexp,
99100 .hljs-link {
100- color: #c2410c; /* orange-700 */
101+ color: #44403c; /* neutral-700 */
101102 }
102103
103104 .prose .hljs-symbol,
104105 .prose .hljs-bullet,
105106 .hljs-symbol,
106107 .hljs-bullet {
107- color: #ea580c; /* orange-600 */
108+ color: #57534e; /* neutral-600 */
108109 }
109110
110111 .prose .hljs-built_in,
111112 .prose .hljs-builtin-name,
112113 .hljs-built_in,
113114 .hljs-builtin-name {
114- color: #4f46e5; /* indigo-600 */
115+ color: #292524; /* neutral-800 */
116+ font-weight: 500;
115117 }
116118
117119 .prose .hljs-meta,
@@ -120,11 +122,11 @@ pre .hljs,
120122 }
121123
122124 .hljs-deletion {
123- background: #fee2e2; /* red-100 */
125+ background: #d4d4d4; /* neutral-300 */
124126 }
125127
126128 .hljs-addition {
127- background: #dcfce7; /* green-100 */
129+ background: #a3a3a3; /* neutral-400 */
128130 }
129131
130132 .hljs-emphasis {
@@ -176,7 +178,7 @@ pre .hljs,
176178 .dark .hljs-keyword,
177179 .dark .hljs-selector-tag,
178180 .dark .hljs-subst {
179- color: #22c55e; /* green-500 */
181+ color: #fafaf9; /* neutral-50 */
180182 font-weight: 600;
181183 }
182184
@@ -190,14 +192,14 @@ pre .hljs,
190192 .dark .hljs-variable,
191193 .dark .hljs-template-variable,
192194 .dark .hljs-tag .hljs-attr {
193- color: #fb923c; /* orange-400 */
195+ color: #d4d4d4; /* neutral-300 */
194196 }
195197
196198 .dark .prose .hljs-string,
197199 .dark .prose .hljs-doctag,
198200 .dark .hljs-string,
199201 .dark .hljs-doctag {
200- color: #fdba74; /* orange-300 */
202+ color: #d6d3d1; /* neutral-300 */
201203 }
202204
203205 .dark .prose .hljs-title,
@@ -206,7 +208,7 @@ pre .hljs,
206208 .dark .hljs-title,
207209 .dark .hljs-section,
208210 .dark .hljs-selector-id {
209- color: #818cf8; /* indigo-400 */
211+ color: #e7e5e4; /* neutral-200 */
210212 font-weight: 600;
211213 }
212214
@@ -214,7 +216,8 @@ pre .hljs,
214216 .dark .prose .hljs-class .hljs-title,
215217 .dark .hljs-type,
216218 .dark .hljs-class .hljs-title {
217- color: #a5b4fc; /* indigo-300 */
219+ color: #e7e5e4; /* neutral-200 */
220+ font-weight: 500;
218221 }
219222
220223 .dark .prose .hljs-tag,
@@ -223,7 +226,7 @@ pre .hljs,
223226 .dark .hljs-tag,
224227 .dark .hljs-name,
225228 .dark .hljs-attribute {
226- color: #22c55e; /* green-500 */
229+ color: #d4d4d4; /* neutral-300 */
227230 font-weight: normal;
228231 }
229232
@@ -231,21 +234,22 @@ pre .hljs,
231234 .dark .prose .hljs-link,
232235 .dark .hljs-regexp,
233236 .dark .hljs-link {
234- color: #fdba74; /* orange-300 */
237+ color: #d6d3d1; /* neutral-300 */
235238 }
236239
237240 .dark .prose .hljs-symbol,
238241 .dark .prose .hljs-bullet,
239242 .dark .hljs-symbol,
240243 .dark .hljs-bullet {
241- color: #fb923c; /* orange-400 */
244+ color: #d4d4d4; /* neutral-300 */
242245 }
243246
244247 .dark .prose .hljs-built_in,
245248 .dark .prose .hljs-builtin-name,
246249 .dark .hljs-built_in,
247250 .dark .hljs-builtin-name {
248- color: #818cf8; /* indigo-400 */
251+ color: #e7e5e4; /* neutral-200 */
252+ font-weight: 500;
249253 }
250254
251255 .dark .prose .hljs-meta,
@@ -254,9 +258,9 @@ pre .hljs,
254258 }
255259
256260 .dark .hljs-deletion {
257- background: #7f1d1d; /* red-900 */
261+ background: #404040; /* neutral-700 */
258262 }
259263
260264 .dark .hljs-addition {
261- background: #14532d; /* green-800 */
265+ background: #525252; /* neutral-600 */
262266 }
app/page.tsx+3−3
@@ -38,12 +38,12 @@ export default function Home() {
3838
3939 return (
4040 <div className="flex h-screen bg-neutral-100 text-neutral-800 dark:bg-neutral-950 dark:text-neutral-200">
41- <div className="flex min-w-0 flex-1 flex-col">
41+ <div className="flex min-w-0 flex-1 flex-col relative">
4242 <div
4343 ref={messagesContainerRef}
44- className="flex-1 overflow-y-auto overflow-x-hidden bg-neutral-100 p-4 dark:bg-neutral-950"
44+ className="flex-1 overflow-y-auto overflow-x-hidden bg-neutral-100 p-4 pb-32 text-neutral-900 dark:bg-neutral-900 dark:text-neutral-100"
4545 >
46- <div className="mx-auto flex min-h-full max-w-5xl flex-col justify-end gap-8">
46+ <div className={`mx-auto flex min-h-full max-w-5xl flex-col gap-8 ${currentThreadId === null ? "justify-center" : "justify-end"}`}>
4747 {currentThreadId === null ? (
4848 <NoThreadSelected threadCount={totalThreadCount} />
4949 ) : (
src/components/Anchor.tsx+15−37
@@ -1,62 +1,40 @@
11 "use client";
22
33 import type { AnchorHTMLAttributes, ReactNode } from "react";
4+import { Children, isValidElement } from "react";
45
56 type AnchorProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
67 children: ReactNode;
78 isSelected?: boolean;
8- color?: string;
99 };
1010
11-// Anchor: A reusable anchor component with customizable selection highlight color.
12-// When selected (isSelected=true), displays a colored border based on the color prop.
13-// When not selected, uses neutral borders with hover effects.
11+// Anchor: A reusable anchor component with neutral hover and selection states.
12+// When selected (isSelected=true), displays a neutral-800 background (dark) or neutral-200 (light).
13+// On hover, displays a neutral-700 background (dark) or neutral-300 (light).
1414 export default function Anchor({
1515 children,
1616 isSelected = false,
17- color = "green",
1817 className = "",
1918 ...props
2019 }: AnchorProps) {
21- // Map color to Tailwind border classes (using full class names for JIT compilation)
22- const getBorderColorClasses = (colorName: string) => {
23- const colorMap: Record<string, string> = {
24- green: "border-green-900 dark:border-green-500",
25- rose: "border-rose-900 dark:border-rose-500",
26- red: "border-red-900 dark:border-red-500",
27- orange: "border-orange-900 dark:border-orange-500",
28- amber: "border-amber-900 dark:border-amber-500",
29- yellow: "border-yellow-900 dark:border-yellow-500",
30- lime: "border-lime-900 dark:border-lime-500",
31- emerald: "border-emerald-900 dark:border-emerald-500",
32- teal: "border-teal-900 dark:border-teal-500",
33- cyan: "border-cyan-900 dark:border-cyan-500",
34- sky: "border-sky-900 dark:border-sky-500",
35- blue: "border-blue-900 dark:border-blue-500",
36- indigo: "border-indigo-900 dark:border-indigo-500",
37- violet: "border-violet-900 dark:border-violet-500",
38- purple: "border-purple-900 dark:border-purple-500",
39- fuchsia: "border-fuchsia-900 dark:border-fuchsia-500",
40- pink: "border-pink-900 dark:border-pink-500",
41- slate: "border-slate-900 dark:border-slate-500",
42- gray: "border-gray-900 dark:border-gray-500",
43- zinc: "border-zinc-900 dark:border-zinc-500",
44- neutral: "border-neutral-900 dark:border-neutral-500",
45- stone: "border-stone-900 dark:border-stone-500",
46- };
47- return colorMap[colorName] || colorMap.green;
48- };
20+ // Process children to wrap text nodes in a truncating span
21+ const processedChildren = Children.map(children, (child) => {
22+ if (typeof child === "string" || typeof child === "number") {
23+ return <span className="min-w-0 truncate">{child}</span>;
24+ }
25+ return child;
26+ });
4927
5028 return (
5129 <a
52- className={`m-1 line-clamp-1 break-words border-b-2 p-1 italic ${
30+ className={`flex items-center gap-1 min-w-0 px-2 py-1 rounded ${
5331 isSelected
54- ? getBorderColorClasses(color)
55- : "border-neutral-300 hover:border-neutral-400 dark:border-neutral-800 dark:hover:border-neutral-700"
32+ ? "bg-neutral-200 dark:bg-neutral-800"
33+ : "hover:bg-neutral-300 dark:hover:bg-neutral-700"
5634 } ${className}`}
5735 {...props}
5836 >
59- {children}
37+ {processedChildren}
6038 </a>
6139 );
6240 }
src/components/MessageInput.tsx+23−21
@@ -2,7 +2,7 @@
22
33 import { useState, useRef, useImperativeHandle, forwardRef, useEffect } from "react";
44 import PaperPlaneIcon from "@/src/components/icons/PaperPlaneIcon";
5-import PrimaryButton from "@/src/components/buttons/PrimaryButton";
5+import BasicButton from "@/src/components/buttons/BasicButton";
66 import type { Message } from "@/src/lib/db/schema";
77
88 type MessageInputProps = {
@@ -103,26 +103,28 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
103103 };
104104
105105 return (
106- <form
107- onSubmit={handleSubmit}
108- className="relative shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.1),0_-2px_4px_-1px_rgba(0,0,0,0.06)] dark:shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.3),0_-2px_4px_-1px_rgba(0,0,0,0.2)]"
109- >
110- <textarea
111- ref={textareaRef}
112- value={input}
113- onChange={(e) => setInput(e.target.value)}
114- onKeyDown={handleKeyDown}
115- placeholder={isLoading ? "Loading answer..." : "Type a message..."}
116- disabled={isLoading}
117- rows={3}
118- className="w-full resize-none overflow-y-auto bg-neutral-200 px-2 py-2 pr-12 placeholder:italic placeholder:text-neutral-600 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:bg-neutral-900 dark:placeholder:text-neutral-400"
119- />
120- <div className="absolute bottom-2 right-2">
121- <PrimaryButton type="submit" disabled={isLoading}>
122- <PaperPlaneIcon className={`h-9 w-9 p-1.5 ${isLoading ? "animate-spin" : ""}`} />
123- </PrimaryButton>
124- </div>
125- </form>
106+ <div className="absolute bottom-0 left-0 right-0 flex justify-center p-4 pointer-events-none">
107+ <form
108+ onSubmit={handleSubmit}
109+ className="relative w-full max-w-5xl bg-neutral-300 dark:bg-neutral-700 rounded-lg shadow-lg m-4 pointer-events-auto"
110+ >
111+ <textarea
112+ ref={textareaRef}
113+ value={input}
114+ onChange={(e) => setInput(e.target.value)}
115+ onKeyDown={handleKeyDown}
116+ placeholder={isLoading ? "Loading answer..." : "Type a message..."}
117+ disabled={isLoading}
118+ rows={3}
119+ className="w-full resize-none overflow-y-auto p-4 pr-12 placeholder:italic placeholder:text-neutral-600 dark:placeholder:text-neutral-400 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 bg-transparent"
120+ />
121+ <div className="absolute bottom-2 right-2">
122+ <BasicButton color="neutral" type="submit" disabled={isLoading}>
123+ <PaperPlaneIcon className={`h-8 w-10 p-1.5 ${isLoading ? "animate-spin" : ""}`} />
124+ </BasicButton>
125+ </div>
126+ </form>
127+ </div>
126128 );
127129 }
128130 );
src/components/MessageList.tsx+0−149
@@ -1,149 +0,0 @@
1-"use client";
2-
3-import { useRef, useEffect, useState } from "react";
4-import ReactMarkdown from "react-markdown";
5-import remarkGfm from "remark-gfm";
6-import rehypeHighlight from "rehype-highlight";
7-import type { Message } from "@/src/lib/db/schema";
8-import "../../app/highlight-theme.css";
9-
10-type MessageListProps = {
11- messages: Message[];
12-};
13-
14-export default function MessageList({ messages }: MessageListProps) {
15- const messageRefs = useRef<Map<number, HTMLDivElement>>(new Map());
16- const prevMessagesLengthRef = useRef<number>(0);
17-
18- useEffect(() => {
19- // Scroll to the start of the newly added message
20- if (messages.length > prevMessagesLengthRef.current) {
21- const newMessage = messages[messages.length - 1];
22- const messageElement = messageRefs.current.get(newMessage.id);
23- if (messageElement) {
24- messageElement.scrollIntoView({ block: "start", behavior: "instant" });
25- }
26- prevMessagesLengthRef.current = messages.length;
27- }
28- }, [messages]);
29-
30- const formatTimestamp = (date: Date | string): string => {
31- const d = typeof date === "string" ? new Date(date) : date;
32- return d.toLocaleString();
33- };
34-
35- const formatGenerationTime = (ms: number | null): string => {
36- if (!ms) return "";
37- if (ms < 1000) return `${ms}ms`;
38- return `${(ms / 1000).toFixed(1)}s`;
39- };
40-
41- const formatToolCalls = (toolCallsJson: string | null): string | null => {
42- if (!toolCallsJson) return null;
43- try {
44- const toolCalls = JSON.parse(toolCallsJson);
45- if (!Array.isArray(toolCalls) || toolCalls.length === 0) return null;
46-
47- // Count occurrences of each tool name
48- const toolCounts: Record<string, number> = {};
49- toolCalls.forEach((tc: any) => {
50- const toolName = tc.function?.name || "unknown";
51- toolCounts[toolName] = (toolCounts[toolName] || 0) + 1;
52- });
53-
54- // Format as "toolName x count"
55- const formatted = Object.entries(toolCounts)
56- .map(([name, count]) => `${name} x ${count}`)
57- .join(", ");
58-
59- return formatted;
60- } catch {
61- return null;
62- }
63- };
64-
65- return (
66- <>
67- {messages.map((msg) => (
68- <div
69- key={msg.id}
70- ref={(el) => {
71- if (el) {
72- messageRefs.current.set(msg.id, el);
73- } else {
74- messageRefs.current.delete(msg.id);
75- }
76- }}
77- className="w-full min-w-0"
78- >
79- <div
80- className={`p-2 ${
81- msg.role === "assistant"
82- ? "prose prose-neutral max-w-none bg-neutral-200 dark:prose-invert dark:bg-neutral-900"
83- : "ml-auto w-1/2 min-w-64 bg-neutral-300 text-right dark:bg-neutral-800"
84- }`}
85- >
86- {msg.role === "assistant" ? (
87- <ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeHighlight]}>
88- {msg.content}
89- </ReactMarkdown>
90- ) : (
91- <UserMessageContent content={msg.content} />
92- )}
93- <div className="mt-1 text-xs text-neutral-600 dark:text-neutral-400">
94- sent on {formatTimestamp(msg.createdAt)}
95- {msg.role === "assistant" && msg.generationTimeMs && (
96- <span className="ml-1">
97- • generated in {formatGenerationTime(msg.generationTimeMs)}
98- </span>
99- )}
100- {msg.role === "assistant" && formatToolCalls(msg.toolCalls) && (
101- <span className="ml-1">• tools: {formatToolCalls(msg.toolCalls)}</span>
102- )}
103- </div>
104- </div>
105- </div>
106- ))}
107- </>
108- );
109-}
110-
111-function UserMessageContent({ content }: { content: string }) {
112- const contentRef = useRef<HTMLDivElement>(null);
113- const [showGradient, setShowGradient] = useState(false);
114-
115- useEffect(() => {
116- const checkOverflow = () => {
117- if (contentRef.current) {
118- const isScrollable = contentRef.current.scrollHeight > contentRef.current.clientHeight;
119- setShowGradient(isScrollable);
120- }
121- };
122-
123- checkOverflow();
124- // Check on resize
125- const resizeObserver = new ResizeObserver(checkOverflow);
126- if (contentRef.current) {
127- resizeObserver.observe(contentRef.current);
128- }
129-
130- return () => {
131- resizeObserver.disconnect();
132- };
133- }, [content]);
134-
135- return (
136- <div className="relative">
137- <div
138- ref={contentRef}
139- className="max-h-48 overflow-y-auto pr-2"
140- style={{ scrollbarWidth: "thin" }}
141- >
142- {content}
143- </div>
144- {showGradient && (
145- <div className="pointer-events-none absolute bottom-0 left-0 right-0 h-8 bg-gradient-to-t from-neutral-300 to-transparent dark:from-neutral-800 dark:to-transparent" />
146- )}
147- </div>
148- );
149-}
src/components/MessageList/AssistantMessage.tsx+66−0
@@ -0,0 +1,66 @@
1+"use client";
2+
3+import ReactMarkdown from "react-markdown";
4+import remarkGfm from "remark-gfm";
5+import rehypeHighlight from "rehype-highlight";
6+import type { Message } from "@/src/lib/db/schema";
7+import "../../../app/highlight-theme.css";
8+
9+type AssistantMessageProps = {
10+ message: Message;
11+};
12+
13+export default function AssistantMessage({ message }: AssistantMessageProps) {
14+ const formatTimestamp = (date: Date | string): string => {
15+ const d = typeof date === "string" ? new Date(date) : date;
16+ return d.toLocaleString();
17+ };
18+
19+ const formatGenerationTime = (ms: number | null): string => {
20+ if (!ms) return "";
21+ if (ms < 1000) return `${ms}ms`;
22+ return `${(ms / 1000).toFixed(1)}s`;
23+ };
24+
25+ const formatToolCalls = (toolCallsJson: string | null): string | null => {
26+ if (!toolCallsJson) return null;
27+ try {
28+ const toolCalls = JSON.parse(toolCallsJson);
29+ if (!Array.isArray(toolCalls) || toolCalls.length === 0) return null;
30+
31+ // Count occurrences of each tool name
32+ const toolCounts: Record<string, number> = {};
33+ toolCalls.forEach((tc: any) => {
34+ const toolName = tc.function?.name || "unknown";
35+ toolCounts[toolName] = (toolCounts[toolName] || 0) + 1;
36+ });
37+
38+ // Format as "toolName x count"
39+ const formatted = Object.entries(toolCounts)
40+ .map(([name, count]) => `${name} x ${count}`)
41+ .join(", ");
42+
43+ return formatted;
44+ } catch {
45+ return null;
46+ }
47+ };
48+
49+ return (
50+ <div className="prose prose-neutral max-w-none dark:prose-invert">
51+ <ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeHighlight]}>
52+ {message.content}
53+ </ReactMarkdown>
54+ <div className="mt-4 text-xs text-neutral-600 dark:text-neutral-400">
55+ generated on {formatTimestamp(message.createdAt)}
56+ {message.generationTimeMs && (
57+ <span className="ml-1"> in {formatGenerationTime(message.generationTimeMs)}</span>
58+ )}
59+ {formatToolCalls(message.toolCalls) && (
60+ <span className="ml-1">• tools: {formatToolCalls(message.toolCalls)}</span>
61+ )}
62+ </div>
63+ </div>
64+ );
65+}
66+
src/components/MessageList/UserMessage.tsx+59−0
@@ -0,0 +1,59 @@
1+"use client";
2+
3+import { useRef, useEffect, useState } from "react";
4+import type { Message } from "@/src/lib/db/schema";
5+
6+type UserMessageProps = {
7+ message: Message;
8+};
9+
10+export default function UserMessage({ message }: UserMessageProps) {
11+ const contentRef = useRef<HTMLDivElement>(null);
12+ const [showGradient, setShowGradient] = useState(false);
13+
14+ const formatTimestamp = (date: Date | string): string => {
15+ const d = typeof date === "string" ? new Date(date) : date;
16+ return d.toLocaleString();
17+ };
18+
19+ useEffect(() => {
20+ const checkOverflow = () => {
21+ if (contentRef.current) {
22+ const isScrollable = contentRef.current.scrollHeight > contentRef.current.clientHeight;
23+ setShowGradient(isScrollable);
24+ }
25+ };
26+
27+ checkOverflow();
28+ // Check on resize
29+ const resizeObserver = new ResizeObserver(checkOverflow);
30+ if (contentRef.current) {
31+ resizeObserver.observe(contentRef.current);
32+ }
33+
34+ return () => {
35+ resizeObserver.disconnect();
36+ };
37+ }, [message.content]);
38+
39+ return (
40+ <div className="ml-auto w-1/2 min-w-64 p-2 rounded-lg bg-neutral-200 dark:bg-neutral-800">
41+ <div className="relative">
42+ <div
43+ ref={contentRef}
44+ className="max-h-48 overflow-y-auto"
45+ style={{ scrollbarWidth: "thin" }}
46+ >
47+ {message.content}
48+ </div>
49+ {showGradient && (
50+ <div className="pointer-events-none absolute bottom-0 left-0 right-0 h-8 bg-gradient-to-t from-neutral-200 to-transparent dark:from-neutral-800 dark:to-transparent" />
51+ )}
52+ </div>
53+ <div className="mt-4 text-right text-xs text-neutral-600 dark:text-neutral-400">
54+ sent on {formatTimestamp(message.createdAt)}
55+ </div>
56+ </div>
57+ );
58+}
59+
src/components/MessageList/index.tsx+54−0
@@ -0,0 +1,54 @@
1+"use client";
2+
3+import { useRef, useEffect } from "react";
4+import type { Message } from "@/src/lib/db/schema";
5+import AssistantMessage from "./AssistantMessage";
6+import UserMessage from "./UserMessage";
7+
8+type MessageListProps = {
9+ messages: Message[];
10+};
11+
12+export default function MessageList({ messages }: MessageListProps) {
13+ const messageRefs = useRef<Map<number, HTMLDivElement>>(new Map());
14+ const prevMessagesLengthRef = useRef<number>(0);
15+
16+ useEffect(() => {
17+ // Scroll to the start of the newly added message
18+ if (messages.length > prevMessagesLengthRef.current) {
19+ const newMessage = messages[messages.length - 1];
20+ const messageElement = messageRefs.current.get(newMessage.id);
21+ if (messageElement) {
22+ messageElement.scrollIntoView({ block: "start", behavior: "instant" });
23+ }
24+ prevMessagesLengthRef.current = messages.length;
25+ }
26+ }, [messages]);
27+
28+ return (
29+ <>
30+ {messages.map((msg) => (
31+ <div
32+ key={msg.id}
33+ ref={(el) => {
34+ if (el) {
35+ messageRefs.current.set(msg.id, el);
36+ } else {
37+ messageRefs.current.delete(msg.id);
38+ }
39+ }}
40+ className="w-full min-w-0"
41+ >
42+ <div className="p-2">
43+ {msg.role === "assistant" ? (
44+ <AssistantMessage message={msg} />
45+ ) : (
46+ <UserMessage message={msg} />
47+ )}
48+ </div>
49+ </div>
50+ ))}
51+ </>
52+ );
53+}
54+
src/components/Sidebar.tsx+38−32
@@ -3,7 +3,6 @@
33 import type { Thread } from "@/src/lib/db/schema";
44 import PlusIcon from "@/src/components/icons/PlusIcon";
55 import ChevronDownIcon from "@/src/components/icons/ChevronDownIcon";
6-import AlternateButton from "@/src/components/buttons/AlternateButton";
76 import Anchor from "@/src/components/Anchor";
87
98 type SidebarProps = {
@@ -28,50 +27,57 @@ export default function Sidebar({
2827 hasMoreThreads,
2928 }: SidebarProps) {
3029 return (
31- <div className="h-full w-64 overflow-y-auto bg-neutral-200 p-1 dark:bg-neutral-900">
30+ <div className="h-full w-64 overflow-y-auto bg-neutral-50 p-1 text-neutral-800 dark:bg-neutral-950 dark:text-neutral-200">
3231 <div className="flex flex-col gap-2 p-4">
3332 <div className="flex flex-col gap-2">
34- <label className="font-semibold">Threads</label>
35- <div className="flex flex-col gap-1">
36- <AlternateButton onClick={() => onCreateNewThread()}>
33+ <label className="text-neutral-500">Threads</label>
34+ <div className="flex flex-col gap-2">
35+ <Anchor href="#" onClick={(e) => {
36+ e.preventDefault();
37+ onCreateNewThread();
38+ }}>
3739 <PlusIcon className="h-4 w-4" />
3840 New Thread
39- </AlternateButton>
40- {threads.length === 0 ? (
41- <div className="px-3 py-2 text-neutral-600 dark:text-neutral-400">No threads yet</div>
42- ) : (
43- threads.map((thread) => {
44- const isSelected = currentThreadId === thread.id;
45- return (
46- <Anchor
47- key={thread.id}
48- href={`#thread-${thread.id}`}
49- onClick={(e) => {
50- e.preventDefault();
51- onThreadSelect(thread.id);
52- }}
53- isSelected={isSelected}
54- color="green"
55- >
56- {thread.title || `Thread ${thread.id}`}
57- </Anchor>
58- );
59- })
60- )}
41+ </Anchor>
42+ <div className="flex flex-col">
43+ {threads.length === 0 ? (
44+ <div className="px-3 py-2 text-neutral-600 dark:text-neutral-400">No threads yet</div>
45+ ) : (
46+ threads.map((thread) => {
47+ const isSelected = currentThreadId === thread.id;
48+ return (
49+ <Anchor
50+ key={thread.id}
51+ href={`#thread-${thread.id}`}
52+ onClick={(e) => {
53+ e.preventDefault();
54+ onThreadSelect(thread.id);
55+ }}
56+ isSelected={isSelected}
57+ >
58+ {thread.title || `Thread ${thread.id}`}
59+ </Anchor>
60+ );
61+ })
62+ )}
63+ </div>
6164 </div>
6265 {hasMoreThreads && (
63- <AlternateButton onClick={() => onLoadMore()}>
64- <ChevronDownIcon className="h-4 w-4" />
66+ <Anchor href="#" className="text-xs" onClick={(e) => {
67+ e.preventDefault();
68+ onLoadMore();
69+ }}>
70+ <ChevronDownIcon className="h-3 w-3 mt-0.5" />
6571 Load More
66- </AlternateButton>
72+ </Anchor>
6773 )}
6874 </div>
6975 <div className="flex flex-col gap-2">
70- <label className="font-semibold">Theme</label>
76+ <label className="text-neutral-500">Theme</label>
7177 <select
7278 value={themeMode}
7379 onChange={(e) => onThemeChange(e.target.value as "device" | "dark" | "light")}
74- className="bg-neutral-100 px-3 py-1 text-neutral-800 focus:outline-none dark:bg-neutral-950 dark:text-neutral-200"
80+ className="bg-neutral-100 px-3 py-1 text-neutral-800 focus:outline-none dark:bg-neutral-900 dark:text-neutral-200"
7581 >
7682 <option value="device">Device</option>
7783 <option value="dark">Dark</option>
src/components/buttons/AlternateButton.tsx+0−24
@@ -1,24 +0,0 @@
1-"use client";
2-
3-import type { ButtonHTMLAttributes, ReactNode } from "react";
4-import BasicButton from "./BasicButton";
5-
6-type AlternateButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
7- children: ReactNode;
8-};
9-
10-// AlternateButton: A compact sidebar/action button using an alternate indigo color palette.
11-// Indigo-200 background with indigo-900 text for light mode, indigo-950 background with indigo-200 text for dark mode.
12-// Designed for sidebar action buttons that shouldn't use the primary project green.
13-// Slightly padded, with gentle color transitions on hover for accessible secondary actions.
14-export default function AlternateButton({
15- children,
16- className = "",
17- ...props
18-}: AlternateButtonProps) {
19- return (
20- <BasicButton color="indigo" className={className} {...props}>
21- {children}
22- </BasicButton>
23- );
24-}
src/components/buttons/PrimaryButton.tsx+0−20
@@ -1,20 +0,0 @@
1-"use client";
2-
3-import type { ButtonHTMLAttributes, ReactNode } from "react";
4-import BasicButton from "./BasicButton";
5-
6-type PrimaryButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
7- children: ReactNode;
8-};
9-
10-// PrimaryButton: Main action button (submit/send/etc.), styled with project primary color.
11-// Uses green-900 (light mode) and green-500 (dark mode) as background;
12-// white text in light mode, dark text in dark mode. Transitions to a lighter green on hover.
13-// Disabled state lowers opacity and disables cursor interaction.
14-export default function PrimaryButton({ children, className = "", ...props }: PrimaryButtonProps) {
15- return (
16- <BasicButton color="green" className={className} {...props}>
17- {children}
18- </BasicButton>
19- );
20-}
src/components/buttons/SecondaryButton.tsx+0−26
@@ -1,26 +0,0 @@
1-"use client";
2-
3-import type { ButtonHTMLAttributes, ReactNode } from "react";
4-import BasicButton from "./BasicButton";
5-
6-type SecondaryButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
7- children: ReactNode;
8- isSelected?: boolean;
9-};
10-
11-// SecondaryButton: A neutral, compact button styled for sidebar selections.
12-// When selected (isSelected=true), displays a green border and a neutral background.
13-// When not selected, uses neutral backgrounds and no border, maintaining visual simplicity.
14-// Designed to fit project style with neutral color palette and color-coded borders only on selection.
15-export default function SecondaryButton({
16- children,
17- isSelected = false,
18- className = "",
19- ...props
20-}: SecondaryButtonProps) {
21- return (
22- <BasicButton color="neutral" className={className} {...props}>
23- {children}
24- </BasicButton>
25- );
26-}