Skip to content

🎥 Make videos programmatically with React

repurpose new composition with

Jonny Burger44e9b975503b
diff --git a/packages/studio-server/src/routes.ts b/packages/studio-server/src/routes.ts
index d6a24ec9a6..0d66dbdd1e 100644
--- a/packages/studio-server/src/routes.ts
+++ b/packages/studio-server/src/routes.ts
@@ -25,7 +25,6 @@ import {getPackageManager} from './preview-server/get-package-manager';
import {handleRequest} from './preview-server/handler';
import type {LiveEventsServer} from './preview-server/live-events';
import {parseRequestBody} from './preview-server/parse-body';
-import {getProjectInfo} from './preview-server/project-info';
import {fetchFolder, getFiles} from './preview-server/public-folder';
import {serveStatic} from './preview-server/serve-static';
@@ -102,17 +101,6 @@ const handleFallback = async ({
);
};
-const handleProjectInfo = async (
- remotionRoot: string,
- _: IncomingMessage,
- response: ServerResponse,
-) => {
- const data = await getProjectInfo(remotionRoot);
- response.setHeader('content-type', 'application/json');
- response.writeHead(200);
- response.end(JSON.stringify(data));
-};
-
const handleFileSource = async ({
method,
remotionRoot,
@@ -327,10 +315,6 @@ export const handleRoutes = ({
}) => {
const url = new URL(request.url as string, 'http://localhost');
- if (url.pathname === '/api/project-info') {
- return handleProjectInfo(remotionRoot, request, response);
- }
-
if (url.pathname === '/api/file-source') {
return handleFileSource({
remotionRoot,
diff --git a/packages/studio/src/components/GlobalKeybindings.tsx b/packages/studio/src/components/GlobalKeybindings.tsx
index a8f5d0ea5a..690bd792fb 100644
--- a/packages/studio/src/components/GlobalKeybindings.tsx
+++ b/packages/studio/src/components/GlobalKeybindings.tsx
@@ -3,6 +3,7 @@ import {useContext, useEffect} from 'react';
import {useKeybinding} from '../helpers/use-keybinding';
import {CheckerboardContext} from '../state/checkerboard';
import {ModalsContext} from '../state/modals';
+import {notificationCenter} from './Notifications/NotificationCenter';
export const GlobalKeybindings: React.FC = () => {
const keybindings = useKeybinding();
@@ -14,9 +15,11 @@ export const GlobalKeybindings: React.FC = () => {
event: 'keypress',
key: 'n',
callback: () => {
- setSelectedModal({
- type: 'new-comp',
- compType: 'composition',
+ notificationCenter.current?.addNotification({
+ content: `To make a new composition, right-click an existing one and select "Duplicate"`,
+ created: Date.now(),
+ duration: 5000,
+ id: String(Math.random()),
});
},
commandCtrlKey: false,
diff --git a/packages/studio/src/components/NewComposition/CopyHint.tsx b/packages/studio/src/components/NewComposition/CopyHint.tsx
deleted file mode 100644
index 735f75c4d7..0000000000
--- a/packages/studio/src/components/NewComposition/CopyHint.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import type {ProjectInfo} from '@remotion/studio-shared';
-import React, {useEffect, useState} from 'react';
-import {LIGHT_TEXT} from '../../helpers/colors';
-
-const style: React.CSSProperties = {
- fontSize: 12,
- color: LIGHT_TEXT,
-};
-
-export const CopyHint: React.FC = () => {
- const [projectInfo, setProjectInfo] = useState<ProjectInfo | null>(null);
-
- useEffect(() => {
- fetch(`/api/project-info`)
- .then((res) => res.json())
- .then((res) => {
- setProjectInfo(res);
- })
- .catch((err) => {
- // eslint-disable-next-line no-console
- console.log('Error fetching info about the project', err);
- setProjectInfo(null);
- });
- }, []);
-
- if (!projectInfo?.rootFile) {
- return null;
- }
-
- return (
- <div style={style}>
- Copy this into <br /> your{' '}
- <span style={style} title={projectInfo.rootFile as string}>
- {projectInfo.relativeRootFile}
- </span>{' '}
- file.
- </div>
- );
-};
diff --git a/packages/studio/src/components/NewComposition/NewCompCode.tsx b/packages/studio/src/components/NewComposition/NewCompCode.tsx
deleted file mode 100644
index 9d29ad306f..0000000000
--- a/packages/studio/src/components/NewComposition/NewCompCode.tsx
+++ /dev/null
@@ -1,112 +0,0 @@
-import React from 'react';
-
-const strColor = '#9ECBFF';
-const consColor = '#79B8FF';
-const propColor = '#B392F0';
-const keywordColor = '#F97583';
-
-const cssReset: React.CSSProperties = {
- fontFamily: 'monospace',
-};
-
-const makeProperty = (
- key: string,
- val: number | string,
- type: 'const' | 'string',
- raw: boolean,
-) => {
- if (raw) {
- return makePropertyRaw(key, val, type);
- }
-
- return [
- ` `,
- <span key={key + 'key'} style={{...cssReset, color: propColor}}>
- {key}
- </span>,
- <span key={key + 'equal'} style={{...cssReset, color: keywordColor}}>
- {'='}
- </span>,
- type === 'string'
- ? [
- <span key={key + 'value'} style={{...cssReset, color: strColor}}>
- {'"'}
- {val}
- {'"'}
- </span>,
- ]
- : [
- '{',
- <span
- key={key + 'value'}
- style={{
- ...cssReset,
- color: typeof val === 'number' ? consColor : strColor,
- }}
- >
- {val}
- </span>,
- '}',
- ],
- <br key={key + 'br'} />,
- ];
-};
-
-const makePropertyRaw = (
- key: string,
- val: number | string,
- type: 'const' | 'string',
-) => {
- return [
- ` `,
- key,
- '=',
- type === 'string' ? ['"' + val + '"'].join('') : ['{', val, '}'].join(''),
- '\n',
- ].join('');
-};
-
-export const getNewCompositionCode = ({
- type,
- height,
- width,
- fps,
- durationInFrames,
- name,
- raw,
-}: {
- type: 'still' | 'composition';
- height: number;
- width: number;
- fps: number;
- durationInFrames: number;
- name: string;
- raw: boolean;
-}) => {
- const compName = type === 'still' ? 'Still' : 'Composition';
-
- const props = [
- ...makeProperty('id', name, 'string', raw),
- ...makeProperty('component', name, 'const', raw),
- ...(type === 'composition'
- ? makeProperty('durationInFrames', durationInFrames, 'const', raw)
- : []),
- ...makeProperty('height', height, 'const', raw),
- ...makeProperty('width', width, 'const', raw),
- ...(type === 'composition' ? makeProperty('fps', fps, 'const', raw) : []),
- ];
-
- if (raw) {
- return ['<', compName, '\n', ...props, '/>'].join('');
- }
-
- return [
- `<`,
- <span key="compname" style={{...cssReset, color: '#79B8FF'}}>
- {compName}
- </span>,
- <br key="linebr1" />,
- ...props,
- '/>',
- ];
-};
diff --git a/packages/studio/src/components/NewComposition/NewComposition.tsx b/packages/studio/src/components/NewComposition/NewComposition.tsx
index cdc7dbb5eb..3b76342492 100644
--- a/packages/studio/src/components/NewComposition/NewComposition.tsx
+++ b/packages/studio/src/components/NewComposition/NewComposition.tsx
@@ -12,8 +12,7 @@ import {
} from '../../state/aspect-ratio-locked';
import type {CompType} from '../../state/modals';
import {ModalsContext} from '../../state/modals';
-import {CopyButton} from '../CopyButton';
-import {Flex, Row, Spacing} from '../layout';
+import {Row, Spacing} from '../layout';
import {
getMaxModalHeight,
getMaxModalWidth,
@@ -22,11 +21,9 @@ import {
import {NewCompHeader} from '../ModalHeader';
import type {ComboboxValue} from './ComboBox';
import {Combobox} from './ComboBox';
-import {CopyHint} from './CopyHint';
import {InputDragger} from './InputDragger';
import {inputArea, leftLabel} from './new-comp-layout';
import {NewCompAspectRatio} from './NewCompAspectRatio';
-import {getNewCompositionCode} from './NewCompCode';
import {NewCompDuration} from './NewCompDuration';
import {RemotionInput} from './RemInput';
import {ValidationMessage} from './ValidationMessage';
@@ -39,35 +36,10 @@ const left: React.CSSProperties = {
fontSize: 13,
};
-const panelRight: React.CSSProperties = {
- backgroundColor: 'black',
- display: 'flex',
- justifyContent: 'center',
- alignItems: 'center',
- position: 'relative',
- width: 400,
-};
-
-const pre: React.CSSProperties = {
- fontSize: 17,
- fontFamily: 'monospace',
-};
-
const comboBoxStyle: React.CSSProperties = {
width: inputArea.width,
};
-const copyRowStyle: React.CSSProperties = {
- position: 'absolute',
- bottom: 10,
- right: 0,
- paddingRight: 10,
- paddingLeft: 20,
- width: '100%',
- alignItems: 'center',
- color: leftLabel.color,
-};
-
const commonFrameRates = [24, 25, 29.97, 30, 48, 50];
const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
@@ -87,7 +59,7 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
return {
flexDirection: 'row',
display: 'flex',
- width: getMaxModalWidth(950),
+ width: getMaxModalWidth(600),
height:
type === 'composition'
? getMaxModalHeight(490)
@@ -404,38 +376,6 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
) : null}
</form>
</div>
- <div style={panelRight}>
- <pre style={pre}>
- {getNewCompositionCode({
- type,
- durationInFrames: Number(durationInFrames),
- fps: Number(selectedFrameRate),
- height: Number(size.height),
- width: Number(size.width),
- name,
- raw: false,
- })}
- </pre>
- <Row align="center" style={copyRowStyle}>
- <CopyHint />
- <Flex />
- <CopyButton
- label="Copy code"
- labelWhenCopied="Copied!"
- textToCopy={
- getNewCompositionCode({
- type,
- durationInFrames: Number(durationInFrames),
- fps: Number(selectedFrameRate),
- height: Number(size.height),
- width: Number(size.width),
- name,
- raw: true,
- }) as string
- }
- />
- </Row>
- </div>{' '}
</div>
</ModalContainer>
);
diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsx
index 3f50000875..4b4e0e4710 100644
--- a/packages/studio/src/helpers/use-menu-structure.tsx
+++ b/packages/studio/src/helpers/use-menu-structure.tsx
@@ -44,59 +44,13 @@ const ICON_SIZE = 16;
const getFileMenu = ({
readOnlyStudio,
closeMenu,
- setSelectedModal,
previewServerState,
}: {
readOnlyStudio: boolean;
closeMenu: () => void;
- setSelectedModal: React.Dispatch<React.SetStateAction<ModalState | null>>;
previewServerState: 'connected' | 'init' | 'disconnected';
}) => {
const items: ComboboxValue[] = [
- readOnlyStudio
- ? null
- : {
- id: 'new-sequence',
- value: 'new-sequence',
- label: 'New composition...',
- onClick: () => {
- closeMenu();
- setSelectedModal({
- compType: 'composition',
- type: 'new-comp',
- });
- },
- type: 'item' as const,
- keyHint: 'N',
- leftItem: null,
- subMenu: null,
- quickSwitcherLabel: 'New composition...',
- },
- readOnlyStudio
- ? null
- : {
- id: 'new-still',
- value: 'new-still',
- label: 'New still...',
- onClick: () => {
- closeMenu();
- setSelectedModal({
- compType: 'still',
- type: 'new-comp',
- });
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- quickSwitcherLabel: 'New still...',
- },
- readOnlyStudio
- ? null
- : {
- type: 'divider' as const,
- id: 'new-divider',
- },
readOnlyStudio
? null
: {
@@ -298,7 +252,6 @@ export const useMenuStructure = (
readOnlyStudio,
closeMenu,
previewServerState: type,
- setSelectedModal,
}),
{
id: 'view' as const,