xonecas.io
53129
Pa

PAT / commit e776ae5

fix: simpler loading state

xonecas2025-12-17 e776ae544bcbc93d969f6f5b5a1b6a49e7cadd51 parent ec00b18

4 files changed

app/globals.css+0−19
@@ -79,23 +79,4 @@
7979 .animate-spin-and-color-cycle {
8080 animation: spin-and-color-cycle 3s linear infinite;
8181 }
82-
83- @keyframes color-cycle {
84- 0% {
85- color: rgb(239 68 68); /* red-500 */
86- }
87- 33.33% {
88- color: rgb(249 115 22); /* orange-500 */
89- }
90- 66.66% {
91- color: rgb(245 158 11); /* amber-500 */
92- }
93- 100% {
94- color: rgb(239 68 68); /* red-500 */
95- }
96- }
97-
98- .animate-color-cycle {
99- animation: color-cycle 3s linear infinite;
100- }
10182 }
app/page.tsx+1−1
@@ -54,6 +54,7 @@ export default function Home() {
5454 <MessageInput
5555 ref={messageInputRef}
5656 isLoading={isLoading}
57+ isLoadingMessages={isLoadingMessages}
5758 messages={messages}
5859 onSubmit={handleSendMessage}
5960 />
@@ -61,7 +62,6 @@ export default function Home() {
6162 <Sidebar
6263 threads={threads}
6364 currentThreadId={currentThreadId}
64- isLoadingThread={isLoadingMessages}
6565 themeMode={themeMode}
6666 onCreateNewThread={handleCreateNewThread}
6767 onThreadSelect={handleThreadSelect}
src/components/MessageInput.tsx+9−6
@@ -7,6 +7,7 @@ import type { Message } from "@/src/lib/db/schema";
77
88 type MessageInputProps = {
99 isLoading: boolean;
10+ isLoadingMessages: boolean;
1011 messages: Message[];
1112 onSubmit: (message: string) => void;
1213 };
@@ -16,7 +17,7 @@ export type MessageInputRef = {
1617 };
1718
1819 const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
19- ({ isLoading, messages, onSubmit }, ref) => {
20+ ({ isLoading, isLoadingMessages, messages, onSubmit }, ref) => {
2021 const [input, setInput] = useState("");
2122 const [historyIndex, setHistoryIndex] = useState<number | null>(null);
2223 const textareaRef = useRef<HTMLTextAreaElement>(null);
@@ -55,11 +56,13 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
5556 textarea.style.height = `${newHeight}px`;
5657 }, [input]);
5758
59+ const isAnyLoading = isLoading || isLoadingMessages;
60+
5861 const handleSubmit = (e?: React.FormEvent) => {
5962 if (e) {
6063 e.preventDefault();
6164 }
62- if (!input.trim() || isLoading) return;
65+ if (!input.trim() || isAnyLoading) return;
6366
6467 const inputValue = input.trim();
6568 onSubmit(inputValue);
@@ -113,15 +116,15 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
113116 value={input}
114117 onChange={(e) => setInput(e.target.value)}
115118 onKeyDown={handleKeyDown}
116- placeholder={isLoading ? "Loading answer..." : "Type a message..."}
117- disabled={isLoading}
119+ placeholder={isAnyLoading ? "Loading..." : "Type a message..."}
120+ disabled={isAnyLoading}
118121 rows={3}
119122 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"
120123 />
121124 <div className="absolute bottom-2 right-2">
122- <BasicButton color="neutral" type="submit" disabled={isLoading}>
125+ <BasicButton color="neutral" type="submit" disabled={isAnyLoading}>
123126 <PaperPlaneIcon
124- className={`h-8 w-10 p-1.5 ${isLoading ? "animate-spin-and-color-cycle" : ""}`}
127+ className={`h-8 w-10 p-1.5 ${isAnyLoading ? "animate-spin-and-color-cycle" : ""}`}
125128 />
126129 </BasicButton>
127130 </div>
src/components/Sidebar.tsx+1−4
@@ -8,7 +8,6 @@ import Anchor from "@/src/components/Anchor";
88 type SidebarProps = {
99 threads: Thread[];
1010 currentThreadId: number | null;
11- isLoadingThread: boolean;
1211 themeMode: "device" | "dark" | "light";
1312 onCreateNewThread: () => void;
1413 onThreadSelect: (threadId: number) => void;
@@ -20,7 +19,6 @@ type SidebarProps = {
2019 export default function Sidebar({
2120 threads,
2221 currentThreadId,
23- isLoadingThread,
2422 themeMode,
2523 onCreateNewThread,
2624 onThreadSelect,
@@ -47,7 +45,6 @@ export default function Sidebar({
4745 ) : (
4846 threads.map((thread) => {
4947 const isSelected = currentThreadId === thread.id;
50- const isLoading = isLoadingThread && isSelected;
5148 return (
5249 <Anchor
5350 key={thread.id}
@@ -58,7 +55,7 @@ export default function Sidebar({
5855 }}
5956 isSelected={isSelected}
6057 >
61- <span className={`min-w-0 truncate ${isLoading ? "animate-color-cycle" : ""}`}>
58+ <span className="min-w-0 truncate">
6259 {thread.title || `Thread ${thread.id}`}
6360 </span>
6461 </Anchor>