Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add JSON and video error toasters #44

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
import { Toaster } from "@/components/ui/sonner";
import { Toaster } from "@/components/ui/toaster";

const geistSans = localFont({
src: "./fonts/GeistVF.woff",
Expand Down
28 changes: 24 additions & 4 deletions ui/src/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
import { useForm } from "react-hook-form";
import { z } from "zod";
import { Select } from "./ui/select";
import { toast } from "sonner";

export interface StreamConfig {
streamUrl: string;
Expand Down Expand Up @@ -170,8 +171,16 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
if (selectedVideoDevice == "none" && videoDevices.length > 1) {
setSelectedVideoDevice(videoDevices[1].deviceId); // Index 1 because 0 is "No Video"
}
} catch (err){
console.log(`Failed to get video devices: ${err}`);
} catch (error) {
console.log(`Failed to get video devices: ${error}`);
toast.error("Failed to get video devices", {
description: "Please make sure your camera is connected and enabled.",
});

// If we can't access video devices, still provide the None option
const videoDevices = [{ deviceId: "none", label: "No Video" }];
setVideoDevices(videoDevices);
setSelectedVideoDevice("none");
}
}, []);

Expand All @@ -194,8 +203,16 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
if (selectedAudioDevice == "none" && audioDevices.length > 1) {
setSelectedAudioDevice(audioDevices[1].deviceId); // Index 1 because 0 is "No Audio"
}
} catch (err) {
console.log(`Failed to get audio devices: ${err}`);
} catch (error) {
console.error("Failed to get audio devices: ", error);
toast.error("Failed to get audio devices", {
description: "Please make sure your microphone is connected and enabled.",
});

// If we can't access audio devices, still provide the None option
const audioDevices = [{ deviceId: "none", label: "No Audio" }];
setAudioDevices(audioDevices);
setSelectedAudioDevice("none");
}
}, []);

Expand Down Expand Up @@ -245,6 +262,9 @@ function ConfigForm({ config, onSubmit }: ConfigFormProps) {
setOriginalPrompts(allPrompts);
} catch (err) {
console.error("Failed to parse one or more JSON files.", err);
toast.error("Failed to Parse Workflow", {
description: "Please upload a valid JSON file.",
});
}
};

Expand Down
31 changes: 0 additions & 31 deletions ui/src/components/ui/sonner.tsx

This file was deleted.

42 changes: 42 additions & 0 deletions ui/src/components/ui/toaster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file Contains a Toaster component that can be used to trigger toast notifications
* from anywhere in the app.
*/
"use client";
import { useTheme } from "next-themes";
import { Toaster as Sonner } from "sonner";

type ToasterProps = React.ComponentProps<typeof Sonner>;

/**
* Toaster component for displaying toast notifications using the `sonner` library.
*
* Add to the layout to trigger notifications anywhere in the app using the `toast`
* method.
*
* @param props - The props for the Toaster component.
*/
const Toaster = ({ ...props }: ToasterProps): JSX.Element => {
const { theme = "system" } = useTheme();

return (
<Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
toastOptions={{
classNames: {
toast:
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
description: "group-[.toast]:text-muted-foreground",
actionButton:
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
cancelButton:
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
},
}}
{...props}
/>
);
};

export { Toaster };