Skip to content

Commit 5f3222b

Browse files
committed
feat: add JSON and video error toasters
This commit ensures that users are aware if there has been an error trying to get their camara devices or parsing of the workflow json.
1 parent 20d76ff commit 5f3222b

File tree

6 files changed

+90
-36
lines changed

6 files changed

+90
-36
lines changed

ui/package-lock.json

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@radix-ui/react-label": "^2.1.2",
1616
"@radix-ui/react-select": "^2.1.6",
1717
"@radix-ui/react-slot": "^1.1.2",
18+
"@radix-ui/react-toast": "^1.2.6",
1819
"@radix-ui/react-tooltip": "^1.1.8",
1920
"class-variance-authority": "^0.7.0",
2021
"clsx": "^2.1.1",

ui/src/app/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Metadata } from "next";
22
import localFont from "next/font/local";
33
import "./globals.css";
4-
import { Toaster } from "@/components/ui/sonner";
4+
import { Toaster } from "@/components/ui/toaster";
55

66
const geistSans = localFont({
77
src: "./fonts/GeistVF.woff",

ui/src/components/settings.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import { useForm } from "react-hook-form";
3434
import { z } from "zod";
3535
import { Select } from "./ui/select";
36+
import { toast } from "sonner";
3637

3738
export interface StreamConfig {
3839
streamUrl: string;
@@ -156,8 +157,11 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
156157
if (videoDevices.length > 0) {
157158
setSelectedDevice((curr) => curr || videoDevices[0].deviceId);
158159
}
159-
} catch (err) {
160-
console.error("Failed to get video devices");
160+
} catch (error){
161+
console.log(`Failed to get video devices: ${error}`);
162+
toast.error("Failed to get video devices", {
163+
description: "Please make sure your camera is connected and enabled.",
164+
});
161165
}
162166
}, []);
163167

@@ -193,8 +197,11 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
193197
const parsedPrompt = JSON.parse(text);
194198
setPrompt(parsedPrompt);
195199
setOriginalPrompt(parsedPrompt);
196-
} catch (err) {
197-
console.error(err);
200+
} catch (error) {
201+
console.error(`Failed to parse prompt: ${error}`);
202+
toast.error("Failed to Parse Workflow", {
203+
description: "Please upload a valid JSON file.",
204+
});
198205
}
199206
};
200207

ui/src/components/ui/sonner.tsx

-31
This file was deleted.

ui/src/components/ui/toaster.tsx

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file Contains a Toaster component that can be used to trigger toast notifications
3+
* from anywhere in the app.
4+
*/
5+
"use client";
6+
import { useTheme } from "next-themes";
7+
import { Toaster as Sonner } from "sonner";
8+
9+
type ToasterProps = React.ComponentProps<typeof Sonner>;
10+
11+
/**
12+
* Toaster component for displaying toast notifications using the `sonner` library.
13+
*
14+
* Add to the layout to trigger notifications anywhere in the app using the `toast`
15+
* method.
16+
*
17+
* @param props - The props for the Toaster component.
18+
*/
19+
const Toaster = ({ ...props }: ToasterProps): JSX.Element => {
20+
const { theme = "system" } = useTheme();
21+
22+
return (
23+
<Sonner
24+
theme={theme as ToasterProps["theme"]}
25+
className="toaster group"
26+
toastOptions={{
27+
classNames: {
28+
toast:
29+
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
30+
description: "group-[.toast]:text-muted-foreground",
31+
actionButton:
32+
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
33+
cancelButton:
34+
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
35+
},
36+
}}
37+
{...props}
38+
/>
39+
);
40+
};
41+
42+
export { Toaster };

0 commit comments

Comments
 (0)