🎥 Make videos programmatically with React
gui render status
Jonny Burger479d3940e62c
diff --git a/packages/cli/src/editor/components/RenderModal/GuiRenderStatus.tsx b/packages/cli/src/editor/components/RenderModal/GuiRenderStatus.tsxindex 2727c1df95..592a6e50f4 100644--- a/packages/cli/src/editor/components/RenderModal/GuiRenderStatus.tsx+++ b/packages/cli/src/editor/components/RenderModal/GuiRenderStatus.tsx@@ -1,13 +1,15 @@-import React from 'react';-import type {BaseRenderProgress} from '../../../preview-server/render-queue/job';+import React, {useCallback, useMemo} from 'react';+import type {RenderJob} from '../../../preview-server/render-queue/job';import type {- AggregateRenderProgress,+ DownloadProgress,RenderingProgressInput,StitchingProgressInput,} from '../../../progress-types';import {LIGHT_TEXT} from '../../helpers/colors';import {Spacing} from '../layout';+import {openInFileExplorer} from '../RenderQueue/actions';import {CircularProgress} from '../RenderQueue/CircularProgress';+import {RenderQueueOpenInFinderItem} from '../RenderQueue/RenderQueueOpenInFolder';import {SuccessIcon} from '../RenderQueue/SuccessIcon';const progressItem: React.CSSProperties = {@@ -26,8 +28,8 @@ const label: React.CSSProperties = {const right: React.CSSProperties = {fontSize: 14,color: LIGHT_TEXT,- width: 100,textAlign: 'right',+ flex: 1,};const BundlingProgress: React.FC<{@@ -92,23 +94,96 @@ const StitchingProgress: React.FC<{);};+const DownloadsProgress: React.FC<{+ downloads: DownloadProgress[];+}> = ({downloads}) => {+ const allHaveProgress = downloads.every((a) => a.totalBytes);+ const totalBytes = allHaveProgress+ ? downloads.reduce((a, b) => a + (b.totalBytes as number), 0)+ : null;+ const downloaded = allHaveProgress+ ? downloads.reduce((a, b) => a + (b.downloaded as number), 0)+ : null;++ const progress = allHaveProgress+ ? (downloaded as number) / (totalBytes as number)+ : 0.1;++ return (+ <div style={progressItem}>+ {progress === 1 ? (+ <SuccessIcon />+ ) : (+ <CircularProgress progress={progress} />+ )}+ <Spacing x={1} />+ <div style={label}>+ Downloading {downloads.length} file{downloads.length === 1 ? '' : 's'}+ </div>+ </div>+ );+};++const OpenFile: React.FC<{+ job: RenderJob;+}> = ({job}) => {+ const labelStyle = useMemo(() => {+ return {+ ...label,+ textAlign: 'left' as const,+ appearance: 'none' as const,+ border: 0,+ paddingLeft: 0,+ cursor: job.deletedOutputLocation ? 'inherit' : 'pointer',+ textDecoration: job.deletedOutputLocation ? 'line-through' : 'none',+ };+ }, [job.deletedOutputLocation]);++ const onClick = useCallback(() => {+ openInFileExplorer({directory: job.outName});+ }, [job.outName]);++ return (+ <div style={progressItem}>+ <SuccessIcon />+ <Spacing x={1} />+ <button style={labelStyle} type="button" onClick={onClick}>+ {job.outName}+ </button>+ <div style={right}>+ <RenderQueueOpenInFinderItem job={job} />+ </div>+ </div>+ );+};+export const GuiRenderStatus: React.FC<{- progress: BaseRenderProgress & AggregateRenderProgress;-}> = ({progress}) => {+ job: RenderJob;+}> = ({job}) => {+ if (job.status === 'idle' || job.status === 'failed') {+ throw new Error(+ 'This component should not be rendered when the job is idle'+ );+ }+return (<div><Spacing y={0.5} /><BundlingProgress- progress={progress.bundling.progress}- doneIn={progress.bundling.doneIn}+ progress={job.progress.bundling.progress}+ doneIn={job.progress.bundling.doneIn}/>- {progress.rendering ? (- <RenderingProgress progress={progress.rendering} />+ {job.progress.rendering ? (+ <RenderingProgress progress={job.progress.rendering} />+ ) : null}+ {job.progress.stitching ? (+ <StitchingProgress progress={job.progress.stitching} />) : null}- {progress.stitching ? (- <StitchingProgress progress={progress.stitching} />+ {job.progress.downloads.length > 0 ? (+ <DownloadsProgress downloads={job.progress.downloads} />) : null}- <Spacing y={2} />+ {job.status === 'done' ? <OpenFile job={job} /> : null}+ <Spacing y={1} /></div>);};diff --git a/packages/cli/src/editor/components/RenderModal/RenderStatusModal.tsx b/packages/cli/src/editor/components/RenderModal/RenderStatusModal.tsxindex f806d0dca4..c36bbd2870 100644--- a/packages/cli/src/editor/components/RenderModal/RenderStatusModal.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderStatusModal.tsx@@ -86,7 +86,7 @@ export const RenderStatusModal: React.FC<{jobId: string}> = ({jobId}) => {</>) : null}{job.status === 'done' || job.status === 'running' ? (- <GuiRenderStatus progress={job.progress} />+ <GuiRenderStatus job={job} />) : null}<div style={spacer} /><div style={buttonRow}>diff --git a/packages/cli/src/editor/components/RenderQueue/RenderQueueItemStatus.tsx b/packages/cli/src/editor/components/RenderQueue/RenderQueueItemStatus.tsxindex cee9245df8..7ffc2a02ad 100644--- a/packages/cli/src/editor/components/RenderQueue/RenderQueueItemStatus.tsx+++ b/packages/cli/src/editor/components/RenderQueue/RenderQueueItemStatus.tsx@@ -1,6 +1,7 @@-import React from 'react';+import React, {useCallback, useContext} from 'react';import type {RenderJob} from '../../../preview-server/render-queue/job';import {FAIL_COLOR, LIGHT_TEXT} from '../../helpers/colors';+import {ModalsContext} from '../../state/modals';import {CircularProgress,RENDER_STATUS_INDICATOR_SIZE,@@ -11,9 +12,26 @@ const iconStyle: React.CSSProperties = {width: RENDER_STATUS_INDICATOR_SIZE,};+const invisibleStyle: React.CSSProperties = {+ appearance: 'none',+ border: 'none',+ padding: 0,+ cursor: 'pointer',+ display: 'flex',+};+export const RenderQueueItemStatus: React.FC<{job: RenderJob;}> = ({job}) => {+ const {setSelectedModal} = useContext(ModalsContext);++ const openProgress = useCallback(() => {+ setSelectedModal({+ type: 'render-progress',+ jobId: job.id,+ });+ }, [job.id, setSelectedModal]);+if (job.status === 'failed') {return (<div>@@ -40,18 +58,24 @@ export const RenderQueueItemStatus: React.FC<{if (job.status === 'done') {return (- <svg style={iconStyle} viewBox="0 0 512 512">- <path- fill={LIGHT_TEXT}- d="M256 512c141.4 0 256-114.6 256-256S397.4 0 256 0S0 114.6 0 256S114.6 512 256 512zM369 209L241 337l-17 17-17-17-64-64-17-17L160 222.1l17 17 47 47L335 175l17-17L385.9 192l-17 17z"- />- </svg>+ <button type="button" style={invisibleStyle} onClick={openProgress}>+ <svg style={iconStyle} viewBox="0 0 512 512">+ <path+ fill={LIGHT_TEXT}+ d="M256 512c141.4 0 256-114.6 256-256S397.4 0 256 0S0 114.6 0 256S114.6 512 256 512zM369 209L241 337l-17 17-17-17-64-64-17-17L160 222.1l17 17 47 47L335 175l17-17L385.9 192l-17 17z"+ />+ </svg>+ </button>);}if (job.status === 'running') {// Add a minimum progress to avoid the progress bar from disappearing- return <CircularProgress progress={Math.max(0.07, job.progress.value)} />;+ return (+ <button type="button" style={invisibleStyle} onClick={openProgress}>+ <CircularProgress progress={Math.max(0.07, job.progress.value)} />+ </button>+ );}throw new Error('Unknown job status');diff --git a/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx b/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsxindex 4cbe3cb275..676424ec84 100644--- a/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx+++ b/packages/cli/src/editor/components/RenderQueue/RenderQueueOutputName.tsx@@ -1,19 +1,19 @@-import React, {useCallback, useContext, useMemo} from 'react';+import React, {useCallback, useMemo} from 'react';import type {RenderJob} from '../../../preview-server/render-queue/job';-import {ModalsContext} from '../../state/modals';+import {sendErrorNotification} from '../Notifications/NotificationCenter';+import {openInFileExplorer} from './actions';import {renderQueueItemSubtitleStyle} from './item-style';export const RenderQueueOutputName: React.FC<{job: RenderJob;}> = ({job}) => {- const {setSelectedModal} = useContext(ModalsContext);-const onClick = useCallback(() => {- setSelectedModal({- type: 'render-progress',- jobId: job.id,+ if (job.deletedOutputLocation) return;++ openInFileExplorer({directory: job.outName}).catch((err) => {+ sendErrorNotification(err.message);});- }, [job, setSelectedModal]);+ }, [job]);const style = useMemo((): React.CSSProperties => {return {