Skip to content

Commit a93858d

Browse files
rickstaaeliteprox
andauthored
feat: add JSON and video error toasters (yondonfu#44)
* 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. * fix setSelectedVideoDevice name from rebase --------- Co-authored-by: Elite <john@eliteencoder.net>
1 parent 125c5d6 commit a93858d

File tree

4 files changed

+67
-36
lines changed

4 files changed

+67
-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

+24-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,16 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
170171
if (selectedVideoDevice == "none" && videoDevices.length > 1) {
171172
setSelectedVideoDevice(videoDevices[1].deviceId); // Index 1 because 0 is "No Video"
172173
}
173-
} catch (err){
174-
console.log(`Failed to get video devices: ${err}`);
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+
180+
// If we can't access video devices, still provide the None option
181+
const videoDevices = [{ deviceId: "none", label: "No Video" }];
182+
setVideoDevices(videoDevices);
183+
setSelectedVideoDevice("none");
175184
}
176185
}, []);
177186

@@ -194,8 +203,16 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
194203
if (selectedAudioDevice == "none" && audioDevices.length > 1) {
195204
setSelectedAudioDevice(audioDevices[1].deviceId); // Index 1 because 0 is "No Audio"
196205
}
197-
} catch (err) {
198-
console.log(`Failed to get audio devices: ${err}`);
206+
} catch (error) {
207+
console.error("Failed to get audio devices: ", error);
208+
toast.error("Failed to get audio devices", {
209+
description: "Please make sure your microphone is connected and enabled.",
210+
});
211+
212+
// If we can't access audio devices, still provide the None option
213+
const audioDevices = [{ deviceId: "none", label: "No Audio" }];
214+
setAudioDevices(audioDevices);
215+
setSelectedAudioDevice("none");
199216
}
200217
}, []);
201218

@@ -245,6 +262,9 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
245262
setOriginalPrompts(allPrompts);
246263
} catch (err) {
247264
console.error("Failed to parse one or more JSON files.", err);
265+
toast.error("Failed to Parse Workflow", {
266+
description: "Please upload a valid JSON file.",
267+
});
248268
}
249269
};
250270

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)