Skip to content

Commit c9a3077

Browse files
committed
Use sooner for errors
1 parent cda65df commit c9a3077

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

chat/bun.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"clsx": "^2.1.1",
1111
"lucide-react": "^0.511.0",
1212
"next": "15.2.4",
13+
"next-themes": "^0.4.6",
1314
"react": "^19.0.0",
1415
"react-dom": "^19.0.0",
16+
"sonner": "^2.0.3",
1517
"tailwind-merge": "^3.3.0",
1618
},
1719
"devDependencies": {
@@ -642,6 +644,8 @@
642644

643645
"next": ["[email protected]", "", { "dependencies": { "@next/env": "15.2.4", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.2.4", "@next/swc-darwin-x64": "15.2.4", "@next/swc-linux-arm64-gnu": "15.2.4", "@next/swc-linux-arm64-musl": "15.2.4", "@next/swc-linux-x64-gnu": "15.2.4", "@next/swc-linux-x64-musl": "15.2.4", "@next/swc-win32-arm64-msvc": "15.2.4", "@next/swc-win32-x64-msvc": "15.2.4", "sharp": "^0.33.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": "dist/bin/next" }, "sha512-VwL+LAaPSxEkd3lU2xWbgEOtrM8oedmyhBqaVNmgKB+GvZlCy9rgaEc+y2on0wv+l0oSFqLtYD6dcC1eAedUaQ=="],
644646

647+
"next-themes": ["[email protected]", "", { "peerDependencies": { "react": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc", "react-dom": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc" } }, "sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA=="],
648+
645649
"object-assign": ["[email protected]", "", {}, "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg=="],
646650

647651
"object-inspect": ["[email protected]", "", {}, "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew=="],
@@ -750,6 +754,8 @@
750754

751755
"slash": ["[email protected]", "", {}, "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q=="],
752756

757+
"sonner": ["[email protected]", "", { "peerDependencies": { "react": "^18.0.0 || ^19.0.0 || ^19.0.0-rc", "react-dom": "^18.0.0 || ^19.0.0 || ^19.0.0-rc" } }, "sha512-njQ4Hht92m0sMqqHVDL32V2Oun9W1+PHO9NDv9FHfJjT3JT22IG4Jpo3FPQy+mouRKCXFWO+r67v6MrHX2zeIA=="],
758+
753759
"source-map-js": ["[email protected]", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="],
754760

755761
"stable-hash": ["[email protected]", "", {}, "sha512-+L3ccpzibovGXFK+Ap/f8LOS0ahMrHTf3xu7mMLSpEGU0EO9ucaysSylKo9eRDFNhWve/y275iPmIZ4z39a9iA=="],

chat/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
"clsx": "^2.1.1",
1919
"lucide-react": "^0.511.0",
2020
"next": "15.2.4",
21+
"next-themes": "^0.4.6",
2122
"react": "^19.0.0",
2223
"react-dom": "^19.0.0",
24+
"sonner": "^2.0.3",
2325
"tailwind-merge": "^3.3.0"
2426
},
2527
"devDependencies": {

chat/src/app/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Metadata } from "next";
22
import { Geist, Geist_Mono } from "next/font/google";
33
import "./globals.css";
4+
import { Toaster } from "@/components/ui/sonner";
45

56
const geistSans = Geist({
67
variable: "--font-geist-sans",
@@ -28,7 +29,8 @@ export default function RootLayout({
2829
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
2930
>
3031
{children}
32+
<Toaster richColors />
3133
</body>
3234
</html>
3335
);
34-
}
36+
}

chat/src/components/ChatInterface.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useState, useEffect, useRef, useCallback } from "react";
44
import MessageList from "./MessageList";
55
import MessageInput from "./MessageInput";
66
import { useSearchParams } from "next/navigation";
7+
import { toast } from "sonner";
78

89
interface Message {
910
role: string;
@@ -149,8 +150,6 @@ export default function ChatInterface() {
149150
};
150151
}, [agentAPIUrl]);
151152

152-
const [error, setError] = useState<string | null>(null);
153-
154153
// Send a new message
155154
const sendMessage = async (
156155
content: string,
@@ -159,9 +158,6 @@ export default function ChatInterface() {
159158
// For user messages, require non-empty content
160159
if (type === "user" && !content.trim()) return;
161160

162-
// Clear any previous errors
163-
setError(null);
164-
165161
// For raw messages, don't set loading state as it's usually fast
166162
if (type === "user") {
167163
setLoading(true);
@@ -190,9 +186,9 @@ export default function ChatInterface() {
190186
: "";
191187

192188
const fullDetail = `${detail}: ${messages}`;
193-
setError(`Failed to send message: ${fullDetail}`);
194-
// Auto-clear error after 5 seconds
195-
setTimeout(() => setError(null), 5000);
189+
toast.error(`Failed to send message`, {
190+
description: fullDetail,
191+
});
196192
}
197193
// eslint-disable-next-line @typescript-eslint/no-explicit-any
198194
} catch (error: any) {
@@ -206,9 +202,9 @@ export default function ChatInterface() {
206202

207203
const fullDetail = `${detail}: ${messages}`;
208204

209-
setError(`Error sending message: ${fullDetail}`);
210-
// Auto-clear error after 5 seconds
211-
setTimeout(() => setError(null), 5000);
205+
toast.error(`Error sending message`, {
206+
description: fullDetail,
207+
});
212208
} finally {
213209
if (type === "user") {
214210
setLoading(false);
@@ -265,18 +261,6 @@ export default function ChatInterface() {
265261
</div>
266262
)}
267263

268-
{error && (
269-
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-2 text-sm relative">
270-
<span className="block sm:inline">{error}</span>
271-
<button
272-
onClick={() => setError(null)}
273-
className="absolute top-0 bottom-0 right-0 px-4 py-2"
274-
>
275-
×
276-
</button>
277-
</div>
278-
)}
279-
280264
<MessageList messages={messages} loading={loading} />
281265
<MessageInput onSendMessage={sendMessage} disabled={loading} />
282266
</main>

chat/src/components/ui/sonner.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use client"
2+
3+
import { useTheme } from "next-themes"
4+
import { Toaster as Sonner, ToasterProps } from "sonner"
5+
6+
const Toaster = ({ ...props }: ToasterProps) => {
7+
const { theme = "system" } = useTheme()
8+
9+
return (
10+
<Sonner
11+
theme={theme as ToasterProps["theme"]}
12+
className="toaster group"
13+
style={
14+
{
15+
"--normal-bg": "var(--popover)",
16+
"--normal-text": "var(--popover-foreground)",
17+
"--normal-border": "var(--border)",
18+
} as React.CSSProperties
19+
}
20+
{...props}
21+
/>
22+
)
23+
}
24+
25+
export { Toaster }

0 commit comments

Comments
 (0)