Skip to content

🎥 Make videos programmatically with React

working

Patric Salvisberg54ccb0dfd2e3
diff --git a/packages/cli/src/editor/components/EditorContent.tsx b/packages/cli/src/editor/components/EditorContent.tsx
index 029ece24cc..6709bf3b0f 100644
--- a/packages/cli/src/editor/components/EditorContent.tsx
+++ b/packages/cli/src/editor/components/EditorContent.tsx
@@ -12,8 +12,7 @@ const noop = () => undefined;
export const EditorContent: React.FC = () => {
const isStill = useIsStill();
const {canvasContent} = useContext(Internals.CompositionManager);
-
- if (canvasContent === null || isStill || canvasContent.type === 'asset') {
+ if (canvasContent === null || isStill || canvasContent?.type === 'asset') {
return <TopPanel />;
}
diff --git a/packages/cli/src/editor/components/InitialCompositionLoader.tsx b/packages/cli/src/editor/components/InitialCompositionLoader.tsx
index ce80410a2e..9acf886cc3 100644
--- a/packages/cli/src/editor/components/InitialCompositionLoader.tsx
+++ b/packages/cli/src/editor/components/InitialCompositionLoader.tsx
@@ -1,7 +1,7 @@
import type React from 'react';
import {useContext, useEffect} from 'react';
import type {AnyComposition} from 'remotion';
-import {Internals} from 'remotion';
+import {getStaticFiles, Internals} from 'remotion';
import type {ExpandedFoldersState} from '../helpers/persist-open-folders';
import {FolderContext} from '../state/folders';
import {getKeysToExpand} from './CompositionSelector';
@@ -64,17 +64,28 @@ export const InitialCompositionLoader: React.FC = () => {
useEffect(() => {
const onchange = () => {
- const newComp = window.location.pathname.substring(1);
- const exists = compositions.find((c) => c.id === newComp);
- if (exists) {
- selectComposition(exists, false);
+ const newCanvas = deriveCanvasContentFromUrl();
+ if (newCanvas && newCanvas?.type === 'composition') {
+ const newComp = window.location.pathname.substring(1);
+ const exists = compositions.find((c) => c.id === newComp);
+ if (exists) {
+ selectComposition(exists, false);
+ }
+ } else if (newCanvas && newCanvas.type === 'asset') {
+ const staticFiles = getStaticFiles();
+ const exists = staticFiles.find((file) => {
+ return file.name === newCanvas.asset;
+ });
+ if (exists) {
+ setCanvasContent(newCanvas);
+ }
}
};
window.addEventListener('popstate', onchange);
return () => window.removeEventListener('popstate', onchange);
- }, [compositions, selectComposition]);
+ }, [compositions, selectComposition, setCanvasContent]);
return null;
};
diff --git a/packages/cli/src/editor/components/Preview.tsx b/packages/cli/src/editor/components/Preview.tsx
index 2072162c08..948e3f8a6e 100644
--- a/packages/cli/src/editor/components/Preview.tsx
+++ b/packages/cli/src/editor/components/Preview.tsx
@@ -91,7 +91,6 @@ const AssetComponent: React.FC<{currentAsset: string}> = ({currentAsset}) => {
const [fileSize, setFileSize] = useState<string>('');
const fileType = getPreviewFileType(currentAsset);
const staticFileSrc = staticFile(currentAsset);
-
useEffect(() => {
fetch(staticFileSrc).then((res) => {
if (!res.ok) {
diff --git a/packages/cli/src/editor/components/ZoomPersistor.tsx b/packages/cli/src/editor/components/ZoomPersistor.tsx
index 7b44cb35a0..04a8bd711d 100644
--- a/packages/cli/src/editor/components/ZoomPersistor.tsx
+++ b/packages/cli/src/editor/components/ZoomPersistor.tsx
@@ -28,7 +28,7 @@ export const deriveCanvasContentFromUrl = (): CanvasContent | null => {
const lastPart = substrings[substrings.length - 1];
if (substrings.includes('assets')) {
- return {type: 'asset', asset: lastPart};
+ return {type: 'asset', asset: window.location.pathname.substring(8)};
}
if (lastPart) {