xonecas.io
53129
Pa

PAT / commit af1ce97

fix: more UI feedback when things are loading/thinking

xonecas2025-12-17 af1ce974bc9a68673fb0f02f702d76e564644641 parent 8879121

7 files changed

app/globals.css+22−0
@@ -83,4 +83,26 @@
8383 .animate-spin-and-color-cycle {
8484 animation: spin-and-color-cycle 4s linear infinite;
8585 }
86+
87+ @keyframes color-cycle {
88+ 0% {
89+ color: rgb(239 68 68); /* red-500 */
90+ }
91+ 25% {
92+ color: rgb(249 115 22); /* orange-500 */
93+ }
94+ 50% {
95+ color: rgb(245 158 11); /* amber-500 */
96+ }
97+ 75% {
98+ color: rgb(234 179 8); /* yellow-500 */
99+ }
100+ 100% {
101+ color: rgb(239 68 68); /* red-500 */
102+ }
103+ }
104+
105+ .animate-color-cycle {
106+ animation: color-cycle 4s linear infinite;
107+ }
86108 }
app/page.tsx+3−2
@@ -16,7 +16,7 @@ export default function Home() {
1616 useThreads();
1717 const { currentThreadId, selectThread, deselectThread, messagesContainerRef } =
1818 useThreadSelection();
19- const { messages, isLoading, sendMessage, clearMessages } = useMessages(currentThreadId);
19+ const { messages, isLoading, isLoadingMessages, sendMessage, clearMessages } = useMessages(currentThreadId);
2020 const messageInputRef = useRef<MessageInputRef>(null);
2121
2222 const handleThreadSelect = (threadId: number) => {
@@ -41,7 +41,7 @@ export default function Home() {
4141 <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 pb-32 text-neutral-900 dark:bg-neutral-900 dark:text-neutral-100"
44+ className="flex-1 overflow-y-auto overflow-x-hidden bg-neutral-100 p-4 pb-80 text-neutral-900 dark:bg-neutral-900 dark:text-neutral-100"
4545 >
4646 <div className={`mx-auto flex min-h-full max-w-5xl flex-col gap-8 ${currentThreadId === null ? "justify-center" : "justify-end"}`}>
4747 {currentThreadId === null ? (
@@ -61,6 +61,7 @@ export default function Home() {
6161 <Sidebar
6262 threads={threads}
6363 currentThreadId={currentThreadId}
64+ isLoadingThread={isLoadingMessages}
6465 themeMode={themeMode}
6566 onCreateNewThread={handleCreateNewThread}
6667 onThreadSelect={handleThreadSelect}
src/components/MessageInput.tsx+1−1
@@ -103,7 +103,7 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
103103 };
104104
105105 return (
106- <div className="absolute bottom-0 left-0 right-0 flex justify-center p-4 pointer-events-none">
106+ <div className="absolute bottom-0 left-0 right-0 z-10 flex justify-center p-1 pointer-events-none">
107107 <form
108108 onSubmit={handleSubmit}
109109 className="relative w-full max-w-5xl bg-neutral-300 dark:bg-neutral-700 rounded-lg shadow-lg m-4 pointer-events-auto"
src/components/MessageList/index.tsx+1−1
@@ -19,7 +19,7 @@ export default function MessageList({ messages }: MessageListProps) {
1919 const newMessage = messages[messages.length - 1];
2020 const messageElement = messageRefs.current.get(newMessage.id);
2121 if (messageElement) {
22- messageElement.scrollIntoView({ block: "start", behavior: "instant" });
22+ messageElement.scrollIntoView({ block: "start", behavior: "smooth" });
2323 }
2424 prevMessagesLengthRef.current = messages.length;
2525 }
src/components/Sidebar.tsx+6−1
@@ -8,6 +8,7 @@ import Anchor from "@/src/components/Anchor";
88 type SidebarProps = {
99 threads: Thread[];
1010 currentThreadId: number | null;
11+ isLoadingThread: boolean;
1112 themeMode: "device" | "dark" | "light";
1213 onCreateNewThread: () => void;
1314 onThreadSelect: (threadId: number) => void;
@@ -19,6 +20,7 @@ type SidebarProps = {
1920 export default function Sidebar({
2021 threads,
2122 currentThreadId,
23+ isLoadingThread,
2224 themeMode,
2325 onCreateNewThread,
2426 onThreadSelect,
@@ -45,6 +47,7 @@ export default function Sidebar({
4547 ) : (
4648 threads.map((thread) => {
4749 const isSelected = currentThreadId === thread.id;
50+ const isLoading = isLoadingThread && isSelected;
4851 return (
4952 <Anchor
5053 key={thread.id}
@@ -55,7 +58,9 @@ export default function Sidebar({
5558 }}
5659 isSelected={isSelected}
5760 >
58- {thread.title || `Thread ${thread.id}`}
61+ <span className={`min-w-0 truncate ${isLoading ? "animate-color-cycle" : ""}`}>
62+ {thread.title || `Thread ${thread.id}`}
63+ </span>
5964 </Anchor>
6065 );
6166 })
src/hooks/useMessages.ts+6−0
@@ -4,8 +4,10 @@ import type { Message } from "@/src/lib/db/schema";
44 export function useMessages(threadId: number | null) {
55 const [messages, setMessages] = useState<Message[]>([]);
66 const [isLoading, setIsLoading] = useState<boolean>(false);
7+ const [isLoadingMessages, setIsLoadingMessages] = useState<boolean>(false);
78
89 const loadMessages = useCallback(async (id: number) => {
10+ setIsLoadingMessages(true);
911 try {
1012 const res = await fetch(`/api/threads/${id}/messages`);
1113 const data = await res.json();
@@ -13,6 +15,8 @@ export function useMessages(threadId: number | null) {
1315 setMessages(loadedMessages);
1416 } catch (error) {
1517 console.error("Failed to load messages", error);
18+ } finally {
19+ setIsLoadingMessages(false);
1620 }
1721 }, []);
1822
@@ -21,6 +25,7 @@ export function useMessages(threadId: number | null) {
2125 loadMessages(threadId);
2226 } else {
2327 setMessages([]);
28+ setIsLoadingMessages(false);
2429 }
2530 }, [threadId, loadMessages]);
2631
@@ -96,6 +101,7 @@ export function useMessages(threadId: number | null) {
96101 return {
97102 messages,
98103 isLoading,
104+ isLoadingMessages,
99105 sendMessage,
100106 clearMessages,
101107 };
src/hooks/useThreadSelection.ts+1−1
@@ -10,7 +10,7 @@ export function useThreadSelection(
1010 useEffect(() => {
1111 // Scroll to top when a thread is selected
1212 if (currentThreadId !== null && messagesContainerRef.current) {
13- messagesContainerRef.current.scrollTop = 0;
13+ messagesContainerRef.current.scrollTo({ top: 0, behavior: "smooth" });
1414 }
1515 }, [currentThreadId]);