🎥 Make videos programmatically with React
awesome
Jonny Burgerd7fb97144e61
diff --git a/packages/convert/app/components/DropZone.tsx b/packages/convert/app/components/DropZone.tsxindex 00483c2d28..842db926cb 100644--- a/packages/convert/app/components/DropZone.tsx+++ b/packages/convert/app/components/DropZone.tsx@@ -1,4 +1,5 @@import React, {useCallback, useState} from 'react';+import {formatBytes} from '~/lib/format-bytes';import {handleDrop} from '~/lib/upload-report';import type {UploadProgress} from '~/lib/upload-with-progress';@@ -24,19 +25,25 @@ type State =type: 'error';err: Error;}- | {type: 'done'; url: string};+ | {type: 'done'; url: string; filename: string; size: number};-export const DropZone: React.FC = () => {+export const DropZone: React.FC<{+ readonly onUrl: (src: string) => void;+}> = ({onUrl}) => {const [progress, setProgress] = useState<State>({type: 'idle'});- const selectVideo = useCallback(async (file: File) => {- setProgress({type: 'waiting-for-presign'});- const url = await handleDrop({- file,- onProgress: (p) => setProgress({type: 'progress', progress: p}),- });- setProgress({type: 'done', url});- }, []);+ const selectVideo = useCallback(+ async (file: File) => {+ setProgress({type: 'waiting-for-presign'});+ const url = await handleDrop({+ file,+ onProgress: (p) => setProgress({type: 'progress', progress: p}),+ });+ setProgress({type: 'done', url, filename: file.name, size: file.size});+ onUrl(url);+ },+ [onUrl],+ );const onDrop: React.DragEventHandler = useCallback(async (e) => {@@ -67,8 +74,10 @@ export const DropZone: React.FC = () => {if (progress.type === 'done') {return (<Container>- <div className="text-muted-foreground font-medium text-sm">- Video uploaded!+ <div className="text-muted-foreground font-medium text-sm text-center">+ File uploaded!+ <br />+ {progress.filename} ({formatBytes(progress.size)})</div></Container>);@@ -101,7 +110,7 @@ export const DropZone: React.FC = () => {{progress.type === 'waiting-for-presign' ? (<div>Starting Upload...</div>) : (- <div>Drag a video or click here</div>+ <div>Drag a file or click here</div>)}</div></div>diff --git a/packages/convert/app/routes/report._index.tsx b/packages/convert/app/routes/report._index.tsxindex 5fa456e223..5de26183a6 100644--- a/packages/convert/app/routes/report._index.tsx+++ b/packages/convert/app/routes/report._index.tsx@@ -1,39 +1,114 @@-import React, {useState} from 'react';+import React, {useCallback, useState} from 'react';import {DropZone} from '~/components/DropZone';import {Page} from '~/components/Page';import {Button} from '~/components/ui/button';import {Card} from '~/components/ui/card';+import {Input} from '~/components/ui/input';import {Label} from '~/components/ui/label';import {RadioGroup, RadioGroupItem} from '~/components/ui/radio';import {Textarea} from '~/components/ui/textarea';+type Product = 'remotion' | 'media-parser' | 'webcodecs';+type Usage = 'public-testset' | 'internally' | 'confidential';++type SubmitStatus =+ | {+ type: 'idle';+ }+ | {+ type: 'submitting';+ }+ | {+ type: 'done';+ }+ | {type: 'error'; err: Error};+const Report: React.FC = () => {const [description, setDescription] = useState('');+ const [url, setUrl] = useState<string | null>(null);+ const [product, setProduct] = useState<Product | null>(null);+ const [usage, setUsage] = useState<Usage | null>(null);+ const [contact, setContact] = useState('');++ const submitPossible = url && description && product && usage && contact;++ const [submitStatus, setSubmitStatus] = useState<SubmitStatus>({+ type: 'idle',+ });++ const submit = useCallback(async () => {+ if (submitStatus.type !== 'idle' && submitStatus.type !== 'error') {+ return;+ }++ setSubmitStatus({type: 'submitting'});++ try {+ await fetch('https://remotion.pro/api/report', {+ method: 'POST',+ body: JSON.stringify({+ url,+ product,+ description,+ usage,+ contact,+ }),+ headers: {+ 'content-type': 'application/json',+ },+ });+ setSubmitStatus({type: 'done'});+ } catch (err) {+ setSubmitStatus({type: 'error', err: err as Error});+ }+ }, [contact, description, product, submitStatus.type, url, usage]);return (<Page className="flex-col"><div className="m-auto max-w-[800px] w-full"><Card className="mx-4 px-8 py-8 mt-12 pt-8"><h1 className="text-3xl font-brand font-black">Report a video</h1>- <DropZone />+ <DropZone+ onUrl={(u) => {+ setUrl(u);+ }}+ /><br /><h2 className="font-brand mt-5 font-bold">Which product has an issue with this video?</h2>- <RadioGroup name="product" defaultValue="remotion" className="mt-3">+ <RadioGroup+ name="product"+ className="mt-3"+ onValueChange={(e: string) => {+ setProduct(e as Product);+ }}+ ><div className="flex items-center space-x-2">- <RadioGroupItem checked value="remotion" id="remotion" />+ <RadioGroupItem+ checked={product === 'remotion'}+ value="remotion"+ id="remotion"+ /><Label htmlFor="remotion">Remotion - <OffthreadVideo></Label></div><div className="flex items-center space-x-2">- <RadioGroupItem value="media-parser" id="media-parser" />+ <RadioGroupItem+ checked={product === 'media-parser'}+ value="media-parser"+ id="media-parser"+ /><Label htmlFor="media-parser">@remotion/media-parser</Label></div><div className="flex items-center space-x-2">- <RadioGroupItem value="webcodecs" id="webcodecs" />+ <RadioGroupItem+ checked={product === 'webcodecs'}+ value="webcodecs"+ id="webcodecs"+ /><Label htmlFor="webcodecs">@remotion/webcodecs or remotion.dev/convert</Label>@@ -44,7 +119,7 @@ const Report: React.FC = () => {<Textareaname="description"className="mt-3"- placeholder="Conversion fails on Chrome"+ placeholder="Enter all information you deem to be relevant"value={description}onChange={(e) => setDescription(e.target.value)}/>@@ -55,28 +130,72 @@ const Report: React.FC = () => {This allows us to write tests for this video and avoid regressions.The testset is public on GitHub.</p>- <RadioGroup id="usage" defaultValue="public-testset" className="mt-3">+ <RadioGroup+ id="usage"+ onValueChange={(e) => {+ setUsage(e as Usage);+ }}+ className="mt-3"+ ><div className="flex items-center space-x-2">- <RadioGroupItem value="public-testset" id="public-testset" />+ <RadioGroupItem+ value="public-testset"+ checked={usage === 'public-testset'}+ id="public-testset"+ /><Label htmlFor="public-testset">Yes, you may commit it to the public testset</Label></div><div className="flex items-center space-x-2">- <RadioGroupItem value="internally" id="internally" />+ <RadioGroupItem+ value="internally"+ checked={usage === 'internally'}+ id="internally"+ /><Label htmlFor="internally">Only internal testing - don{"'"}t commit to the public testset</Label></div><div className="flex items-center space-x-2">- <RadioGroupItem value="confidential" id="confidential" />+ <RadioGroupItem+ value="confidential"+ checked={usage === 'confidential'}+ id="confidential"+ /><Label htmlFor="confidential">Confidential - delete the video after testing</Label></div></RadioGroup>+ <h2 className="font-brand mt-5 font-bold">+ Your email / Discord username+ </h2>+ <p className="text-muted-foreground text-sm">+ For any follow-up questions, or to notify you when the issue is+ fixed.+ </p>++ <Input+ name="description"+ className="mt-3"+ placeholder="Your Email"+ value={contact}+ onChange={(e) => setContact(e.target.value)}+ />+<div className="h-8" />- <Button type="submit">Submit</Button>+ <Button onClick={submit} disabled={!submitPossible} type="submit">+ Submit+ </Button>+ {submitStatus.type === 'done' && (+ <p className="text-green-500 mt-4">Report submitted!</p>+ )}+ {submitStatus.type === 'error' && (+ <p className="text-red-500 mt-4">+ An error occurred: {submitStatus.err.message}+ </p>+ )}</Card></div></Page>