🎥 Make videos programmatically with React
Show asset info when asset is selected in sidebar
Jonny Burger3a0c3dd6f40a
diff --git a/packages/studio/src/components/AssetSelector.tsx b/packages/studio/src/components/AssetSelector.tsxindex 047c549563..8f6dd0ac4b 100644--- a/packages/studio/src/components/AssetSelector.tsx+++ b/packages/studio/src/components/AssetSelector.tsx@@ -5,6 +5,7 @@ import React, {useMemo,useState,} from 'react';+import {Internals} from 'remotion';import {getStaticFiles, type StaticFile} from '../api/get-static-files';import {writeStaticFile} from '../api/write-static-file';import {StudioServerConnectionCtx} from '../helpers/client-id';@@ -16,6 +17,7 @@ import useAssetDragEvents from '../helpers/use-asset-drag-events';import {FolderContext} from '../state/folders';import {useZIndex} from '../state/z-index';import {AssetFolderTree} from './AssetSelectorItem';+import {CURRENT_ASSET_HEIGHT, CurrentAsset} from './CurrentAsset';import {inlineCodeSnippet} from './Menu/styles';import {showNotification} from './Notifications/NotificationCenter';@@ -43,8 +45,7 @@ const label: React.CSSProperties = {fontSize: 14,};-const list: React.CSSProperties = {- height: '100%',+const baseList: React.CSSProperties = {overflowY: 'auto',};@@ -57,6 +58,7 @@ export const AssetSelector: React.FC<{readonly readOnlyStudio: boolean;}> = ({readOnlyStudio}) => {const {tabIndex} = useZIndex();+ const {canvasContent} = useContext(Internals.CompositionManager);const {assetFoldersExpanded, setAssetFoldersExpanded} =useContext(FolderContext);const [dropLocation, setDropLocation] = useState<string | null>(null);@@ -65,6 +67,17 @@ export const AssetSelector: React.FC<{.previewServerState.type;const shouldAllowUpload = connectionStatus === 'connected' && !readOnlyStudio;+ const showCurrentAsset = canvasContent?.type === 'asset';++ const list: React.CSSProperties = useMemo(() => {+ return {+ ...baseList,+ height: showCurrentAsset+ ? `calc(100% - ${CURRENT_ASSET_HEIGHT}px)`+ : '100%',+ };+ }, [showCurrentAsset]);+const [{publicFolderExists, staticFiles}, setState] = React.useState<State>(() => {return {@@ -162,6 +175,7 @@ export const AssetSelector: React.FC<{onDragOver={shouldAllowUpload ? onDragOver : undefined}onDrop={shouldAllowUpload ? onDrop : undefined}>+ {showCurrentAsset ? <CurrentAsset /> : null}{staticFiles.length === 0 ? (publicFolderExists ? (<div style={emptyState}>diff --git a/packages/studio/src/components/CurrentAsset.tsx b/packages/studio/src/components/CurrentAsset.tsxnew file mode 100644index 0000000000..de5bc487a0--- /dev/null+++ b/packages/studio/src/components/CurrentAsset.tsx@@ -0,0 +1,75 @@+import {formatBytes} from '@remotion/studio-shared';+import React, {useContext, useMemo} from 'react';+import {Internals} from 'remotion';+import {getStaticFiles} from '../api/get-static-files';+import {BACKGROUND, BORDER_COLOR} from '../helpers/colors';++export const CURRENT_ASSET_HEIGHT = 80;++const container: React.CSSProperties = {+ height: CURRENT_ASSET_HEIGHT,+ display: 'block',+ borderBottom: `1px solid ${BORDER_COLOR}`,+ padding: 12,+ color: 'white',+ backgroundColor: BACKGROUND,+};++const title: React.CSSProperties = {+ fontWeight: 'bold',+ fontSize: 12,+ whiteSpace: 'nowrap',+ lineHeight: '18px',+ backgroundColor: BACKGROUND,+};++const subtitle: React.CSSProperties = {+ fontSize: 12,+ opacity: 0.8,+ whiteSpace: 'nowrap',+ lineHeight: '18px',+ backgroundColor: BACKGROUND,+};++const row: React.CSSProperties = {+ display: 'flex',+ flexDirection: 'row',+ lineHeight: '18px',+ backgroundColor: BACKGROUND,+};++export const CurrentAsset: React.FC = () => {+ const {canvasContent} = useContext(Internals.CompositionManager);++ const assetName =+ canvasContent?.type === 'asset' ? canvasContent.asset : null;++ const sizeInBytes = useMemo(() => {+ if (!assetName) {+ return null;+ }++ const staticFiles = getStaticFiles();+ const file = staticFiles.find((f) => f.name === assetName);+ return file?.sizeInBytes ?? null;+ }, [assetName]);++ if (!assetName) {+ return <div style={container} />;+ }++ const fileName = assetName.split('/').pop() ?? assetName;++ return (+ <div style={container}>+ <div style={row}>+ <div>+ <div style={title}>{fileName}</div>+ {sizeInBytes !== null ? (+ <div style={subtitle}>{formatBytes(sizeInBytes)}</div>+ ) : null}+ </div>+ </div>+ </div>+ );+};