🎥 Make videos programmatically with React
alright
Jonny Burger456eda583d9a
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx b/packages/cli/src/editor/components/RenderModal/RenderModal.tsxindex f21a364d15..648e329556 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx@@ -15,6 +15,7 @@ import {Spacing} from '../layout';import {ModalContainer} from '../ModalContainer';import {NewCompHeader} from '../ModalHeader';import {RemotionInput} from '../NewComposition/RemInput';+import {leftSidebarTabs} from '../SidebarContent';type State =| {@@ -102,6 +103,7 @@ export const RenderModal: React.FC<{composition: TCompMetadata}> = ({type: 'still',outName,};+ leftSidebarTabs.current?.selectRendersPanel();fetch(`/api/render`, {method: 'post',headers: {diff --git a/packages/cli/src/editor/components/RenderQueue/RenderQueueItem.tsx b/packages/cli/src/editor/components/RenderQueue/RenderQueueItem.tsxindex 06a7eb65f8..88e560add3 100644--- a/packages/cli/src/editor/components/RenderQueue/RenderQueueItem.tsx+++ b/packages/cli/src/editor/components/RenderQueue/RenderQueueItem.tsx@@ -11,7 +11,7 @@ const container: React.CSSProperties = {};const title: React.CSSProperties = {- fontSize: 14,+ fontSize: 13,lineHeight: 1,};diff --git a/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx b/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsxindex 0939a79a7b..af5eead63d 100644--- a/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx+++ b/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx@@ -8,7 +8,7 @@ import {SPACING_UNIT} from '../layout';import {notificationCenter} from '../Notifications/NotificationCenter';const outputLocation: React.CSSProperties = {- fontSize: 14,+ fontSize: 13,color: LIGHT_TEXT,appearance: 'none',border: 'none',diff --git a/packages/cli/src/editor/components/RenderQueue/index.tsx b/packages/cli/src/editor/components/RenderQueue/index.tsxindex 080c07266e..fa24ffb6a0 100644--- a/packages/cli/src/editor/components/RenderQueue/index.tsx+++ b/packages/cli/src/editor/components/RenderQueue/index.tsx@@ -1,15 +1,23 @@import React, {useContext} from 'react';+import {BORDER_COLOR} from '../../helpers/colors';import {RenderQueueContext} from './context';import {RenderQueueItem} from './RenderQueueItem';+const separatorStyle: React.CSSProperties = {+ borderBottom: '1px solid ' + BORDER_COLOR,+};+export const RenderQueue: React.FC = () => {const {jobs} = useContext(RenderQueueContext);return (<div>- {jobs.map((j) => {+ {jobs.map((j, index) => {return (- <div key={j.id}>+ <div+ key={j.id}+ style={index === jobs.length - 1 ? undefined : separatorStyle}+ ><RenderQueueItem job={j} /></div>);diff --git a/packages/cli/src/editor/components/RendersTab.tsx b/packages/cli/src/editor/components/RendersTab.tsxnew file mode 100644index 0000000000..196311e1fa--- /dev/null+++ b/packages/cli/src/editor/components/RendersTab.tsx@@ -0,0 +1,56 @@+import type {MouseEventHandler} from 'react';+import React, {useContext, useMemo} from 'react';+import {FAIL_COLOR} from '../helpers/colors';+import {Spacing} from './layout';+import {RenderQueueContext} from './RenderQueue/context';+import {Tab} from './Tabs';++const row: React.CSSProperties = {+ display: 'flex',+ flexDirection: 'row',+ fontSize: 13,+ justifyContent: 'center',+ color: 'inherit',+ alignItems: 'center',+};++const badge: React.CSSProperties = {+ height: 16,+ width: 16,+ borderRadius: 8,+ fontSize: 10,+ display: 'inline-flex',+ justifyContent: 'center',+ alignItems: 'center',+};++export const RendersTab: React.FC<{+ selected: boolean;+ onClick: MouseEventHandler<HTMLButtonElement>;+}> = ({selected, onClick}) => {+ const {jobs} = useContext(RenderQueueContext);++ const failedJobs = jobs.filter((j) => j.status === 'failed').length;+ const jobCount = jobs.length;++ const badgeStyle: React.CSSProperties = useMemo(() => {+ return {+ ...badge,+ backgroundColor: failedJobs > 0 ? FAIL_COLOR : 'white',+ };+ }, [failedJobs]);++ return (+ <Tab selected={selected} onClick={onClick}>+ <div style={row}>+ Renders+ {failedJobs ? (+ <>+ <Spacing x={0.5} />+ <div style={badgeStyle}>{jobCount}</div>+ </>+ ) : null}+ </div>+ </Tab>+ );+};diff --git a/packages/cli/src/editor/components/SidebarContent.tsx b/packages/cli/src/editor/components/SidebarContent.tsxindex a24282333b..805b49027b 100644--- a/packages/cli/src/editor/components/SidebarContent.tsx+++ b/packages/cli/src/editor/components/SidebarContent.tsx@@ -1,7 +1,13 @@-import React, {useCallback, useState} from 'react';+import React, {+ createRef,+ useCallback,+ useImperativeHandle,+ useState,+} from 'react';import {BORDER_COLOR} from '../helpers/colors';import {CompositionSelector} from './CompositionSelector';import {RenderQueue} from './RenderQueue';+import {RendersTab} from './RendersTab';import {Tab, Tabs} from './Tabs';type SidebarPanel = 'compositions' | 'renders';@@ -15,6 +21,10 @@ const tabsContainer: React.CSSProperties = {borderBottom: `1px solid ${BORDER_COLOR}`,};+export const leftSidebarTabs = createRef<{+ selectRendersPanel: () => void;+}>();+export const SidebarContent: React.FC = () => {const [panel, setPanel] = useState<SidebarPanel>('compositions');@@ -26,6 +36,16 @@ export const SidebarContent: React.FC = () => {setPanel('renders');}, []);+ useImperativeHandle(+ leftSidebarTabs,+ () => {+ return {+ selectRendersPanel: () => setPanel('renders'),+ };+ },+ []+ );+return (<div style={container}><div style={tabsContainer}>@@ -36,9 +56,10 @@ export const SidebarContent: React.FC = () => {>Compositions</Tab>- <Tab selected={panel === 'renders'} onClick={onRendersSelected}>- Renders- </Tab>+ <RendersTab+ onClick={onRendersSelected}+ selected={panel === 'renders'}+ /></Tabs></div>{panel === 'compositions' ? <CompositionSelector /> : <RenderQueue />}diff --git a/packages/cli/src/event-source-events.ts b/packages/cli/src/event-source-events.tsindex 53689c335f..4f09f8040e 100644--- a/packages/cli/src/event-source-events.ts+++ b/packages/cli/src/event-source-events.ts@@ -15,4 +15,9 @@ export type EventSourceEvent =| {type: 'render-queue-updated';queue: RenderJob[];+ }+ | {+ type: 'render-job-failed';+ compositionId: string;+ error: Error;};diff --git a/packages/cli/src/event-source.ts b/packages/cli/src/event-source.tsindex a6f886d719..2fb1aaae6b 100644--- a/packages/cli/src/event-source.ts+++ b/packages/cli/src/event-source.ts@@ -1,3 +1,4 @@+import {notificationCenter} from './editor/components/Notifications/NotificationCenter';import {serverDisconnectedRef} from './editor/components/Notifications/ServerDisconnected';import {renderJobsRef} from './editor/components/RenderQueue/context';import type {EventSourceEvent} from './event-source-events';@@ -19,6 +20,15 @@ export const openEventSource = () => {if (newEvent.type === 'render-queue-updated') {renderJobsRef.current?.updateRenderJobs(newEvent.queue);}++ if (newEvent.type === 'render-job-failed') {+ notificationCenter.current?.addNotification({+ content: `Rendering "${newEvent.compositionId}" failed`,+ duration: 2000,+ created: Date.now(),+ id: String(Math.random()).replace('0.', ''),+ });+ }});source.addEventListener('open', () => {diff --git a/packages/cli/src/preview-server/render-queue/index.ts b/packages/cli/src/preview-server/render-queue/index.tsindex d164c07c18..0e3a2d320b 100644--- a/packages/cli/src/preview-server/render-queue/index.ts+++ b/packages/cli/src/preview-server/render-queue/index.ts@@ -95,5 +95,13 @@ export const processJobIfPossible = async (entryPoint: string) => {error: err as Error,};});++ waitForLiveEventsListener().then((listener) => {+ listener.sendEventToClient({+ type: 'render-job-failed',+ compositionId: nextJob.compositionId,+ error: err as Error,+ });+ });}};