Skip to content

Commit 4fbe1c9

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 9045ade commit 4fbe1c9

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
import { useForm } from "react-hook-form";
3737
import { z } from "zod";
3838
import { Select } from "./ui/select";
39+
import { toast } from "sonner";
3940

4041
export interface StreamConfig {
4142
streamUrl: string;
@@ -170,8 +171,12 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
170171
if (!selectedDevice && videoDevices.length > 1) {
171172
setSelectedDevice(videoDevices[1].deviceId); // Index 1 because 0 is "No Video"
172173
}
173-
} catch (err) {
174-
console.error("Failed to get video devices");
174+
} catch (error) {
175+
console.log(`Failed to get video devices: ${error}`);
176+
toast.error("Failed to get video devices", {
177+
description: "Please make sure your camera is connected and enabled.",
178+
});
179+
175180
// If we can't access video devices, still provide the None option
176181
const videoDevices = [{ deviceId: "none", label: "No Video" }];
177182
setVideoDevices(videoDevices);
@@ -197,8 +202,12 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
197202
if (!selectedAudioDevice && audioDevices.length > 1) {
198203
setSelectedAudioDevice(audioDevices[0].deviceId); // Default to "No Audio" for now
199204
}
200-
} catch (err) {
201-
console.error("Failed to get audio devices");
205+
} catch (error) {
206+
console.error("Failed to get audio devices: ", error);
207+
toast.error("Failed to get audio devices", {
208+
description: "Please make sure your microphone is connected and enabled.",
209+
});
210+
202211
// If we can't access audio devices, still provide the None option
203212
const audioDevices = [{ deviceId: "none", label: "No Audio" }];
204213
setAudioDevices(audioDevices);
@@ -252,6 +261,9 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
252261
setOriginalPrompts(allPrompts);
253262
} catch (err) {
254263
console.error("Failed to parse one or more JSON files.", err);
264+
toast.error("Failed to Parse Workflow", {
265+
description: "Please upload a valid JSON file.",
266+
});
255267
}
256268
};
257269

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)