Skip to content

🎥 Make videos programmatically with React

Separate ErrorDisplay from AnimationPlayer

ASchwad96972f83a074
diff --git a/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer/index.tsx b/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer/index.tsx
index fab6af7409..592b9e0a8e 100644
--- a/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer/index.tsx
+++ b/packages/template-prompt-to-motion-graphics/src/components/AnimationPlayer/index.tsx
@@ -2,6 +2,7 @@
import React from "react";
import { Player, type ErrorFallback } from "@remotion/player";
+import { ErrorDisplay, type ErrorType } from "../ErrorDisplay";
import { RenderControls } from "./RenderControls";
import { SettingsModal } from "./SettingsModal";
@@ -29,7 +30,7 @@ interface AnimationPlayerProps {
isCompiling: boolean;
isStreaming: boolean;
error: string | null;
- errorType?: "compilation" | "api" | "validation";
+ errorType?: ErrorType;
code: string;
}
@@ -66,24 +67,7 @@ export const AnimationPlayer: React.FC<AnimationPlayerProps> = ({
}
if (error) {
- const errorTitle =
- errorType === "validation"
- ? "Invalid Prompt"
- : errorType === "api"
- ? "API Error"
- : "Compilation Error";
- return (
- <div className="w-full aspect-video max-h-[calc(100%-80px)] flex justify-center items-center bg-background-error rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)] border border-destructive">
- <div className="text-center max-w-[80%]">
- <div className="text-destructive text-base font-semibold mb-2 font-sans">
- {errorTitle}
- </div>
- <div className="text-destructive-foreground text-sm font-mono whitespace-pre-wrap break-words">
- {error}
- </div>
- </div>
- </div>
- );
+ return <ErrorDisplay error={error} errorType={errorType} />;
}
if (!Component) {
diff --git a/packages/template-prompt-to-motion-graphics/src/components/ErrorDisplay.tsx b/packages/template-prompt-to-motion-graphics/src/components/ErrorDisplay.tsx
new file mode 100644
index 0000000000..dfc9a093df
--- /dev/null
+++ b/packages/template-prompt-to-motion-graphics/src/components/ErrorDisplay.tsx
@@ -0,0 +1,34 @@
+"use client";
+
+import React from "react";
+
+export type ErrorType = "compilation" | "api" | "validation";
+
+interface ErrorDisplayProps {
+ error: string;
+ errorType: ErrorType;
+}
+
+const errorTitles: Record<ErrorType, string> = {
+ validation: "Invalid Prompt",
+ api: "API Error",
+ compilation: "Compilation Error",
+};
+
+export const ErrorDisplay: React.FC<ErrorDisplayProps> = ({
+ error,
+ errorType,
+}) => {
+ return (
+ <div className="w-full aspect-video max-h-[calc(100%-80px)] flex justify-center items-center bg-background-error rounded-lg overflow-hidden shadow-[0_0_60px_rgba(0,0,0,0.5)] border border-destructive">
+ <div className="text-center max-w-[80%]">
+ <div className="text-destructive text-base font-semibold mb-2 font-sans">
+ {errorTitles[errorType]}
+ </div>
+ <div className="text-destructive-foreground text-sm font-mono whitespace-pre-wrap break-words">
+ {error}
+ </div>
+ </div>
+ </div>
+ );
+};