🎥 Make videos programmatically with React
Update use-menu-structure.tsx
Jonny Burgerbe092f12041a
diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsxindex 5caec12da3..49efede62c 100644--- a/packages/studio/src/helpers/use-menu-structure.tsx+++ b/packages/studio/src/helpers/use-menu-structure.tsx@@ -3,7 +3,10 @@ import {Internals} from 'remotion';import {NoReactInternals} from 'remotion/no-react';import {Row} from '../components/layout';import type {Menu} from '../components/Menu/MenuItem';-import type {SelectionItem} from '../components/NewComposition/ComboBox';+import type {+ ComboboxValue,+ SelectionItem,+} from '../components/NewComposition/ComboBox';import {sendErrorNotification} from '../components/Notifications/NotificationCenter';import type {TQuickSwitcherResult} from '../components/QuickSwitcher/QuickSwitcherResult';import {getPreviewSizeLabel, getUniqueSizes} from '../components/SizeSelector';@@ -37,6 +40,143 @@ const rotate: React.CSSProperties = {};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+ : {+ id: 'render',+ value: 'render',+ label: 'Render...',+ onClick: () => {+ closeMenu();+ if (previewServerState !== 'connected') {+ sendErrorNotification('Restart the studio to render');+ return;+ }++ const renderButton = document.getElementById(+ 'render-modal-button',+ ) as HTMLDivElement;++ renderButton.click();+ },+ type: 'item' as const,+ keyHint: 'R',+ leftItem: null,+ subMenu: null,+ quickSwitcherLabel: 'Render...',+ },+ window.remotion_editorName && !readOnlyStudio+ ? {+ type: 'divider' as const,+ id: 'open-in-editor-divider',+ }+ : null,+ window.remotion_editorName && !readOnlyStudio+ ? {+ id: 'open-in-editor',+ value: 'open-in-editor',+ label: `Open in ${window.remotion_editorName}`,+ onClick: async () => {+ await openInEditor({+ originalFileName: `${window.remotion_cwd}`,+ originalLineNumber: 1,+ originalColumnNumber: 1,+ originalFunctionName: null,+ originalScriptCode: null,+ })+ .then((res) => res.json())+ .then(({success}) => {+ if (!success) {+ sendErrorNotification(+ `Could not open ${window.remotion_editorName}`,+ );+ }+ })+ .catch((err) => {+ // eslint-disable-next-line no-console+ console.error(err);+ sendErrorNotification(+ `Could not open ${window.remotion_editorName}`,+ );+ });+ },+ type: 'item' as const,+ keyHint: null,+ leftItem: null,+ subMenu: null,+ quickSwitcherLabel: 'Open in editor...',+ }+ : null,+ ].filter(NoReactInternals.truthy);+ if (items.length === 0) {+ return null;+ }++ return {+ id: 'file' as const,+ label: 'File',+ leaveLeftPadding: false,+ items,+ quickSwitcherLabel: null,+ };+};+export const useMenuStructure = (closeMenu: () => void,readOnlyStudio: boolean,@@ -136,138 +276,12 @@ export const useMenuStructure = (],quickSwitcherLabel: null,},- {- id: 'file' as const,- label: 'File',- leaveLeftPadding: false,- items: [- readOnlyStudio- ? {- id: 'read-only',- value: 'replace-me',- label: '// TODO',- onClick: () => {- closeMenu();- },- type: 'item' as const,- keyHint: 'A',- leftItem: null,- subMenu: null,- // TODO: Replace me- quickSwitcherLabel: 'TODO Replace me...',- }- : {- 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- : {- id: 'render',- value: 'render',- label: 'Render...',- onClick: () => {- closeMenu();- if (type !== 'connected') {- sendErrorNotification('Restart the studio to render');- return;- }-- const renderButton = document.getElementById(- 'render-modal-button',- ) as HTMLDivElement;-- renderButton.click();- },- type: 'item' as const,- keyHint: 'R',- leftItem: null,- subMenu: null,- quickSwitcherLabel: 'Render...',- },- window.remotion_editorName && !readOnlyStudio- ? {- type: 'divider' as const,- id: 'open-in-editor-divider',- }- : null,- window.remotion_editorName && !readOnlyStudio- ? {- id: 'open-in-editor',- value: 'open-in-editor',- label: `Open in ${window.remotion_editorName}`,- onClick: async () => {- await openInEditor({- originalFileName: `${window.remotion_cwd}`,- originalLineNumber: 1,- originalColumnNumber: 1,- originalFunctionName: null,- originalScriptCode: null,- })- .then((res) => res.json())- .then(({success}) => {- if (!success) {- sendErrorNotification(- `Could not open ${window.remotion_editorName}`,- );- }- })- .catch((err) => {- // eslint-disable-next-line no-console- console.error(err);- sendErrorNotification(- `Could not open ${window.remotion_editorName}`,- );- });- },- type: 'item' as const,- keyHint: null,- leftItem: null,- subMenu: null,- quickSwitcherLabel: 'Open in editor...',- }- : null,- ].filter(NoReactInternals.truthy),- quickSwitcherLabel: null,- },+ getFileMenu({+ readOnlyStudio,+ closeMenu,+ previewServerState: type,+ setSelectedModal,+ }),{id: 'view' as const,label: 'View',