🎥 Make videos programmatically with React
Can drop multiple files in Studio
Jonny Burger543adb39dad0
diff --git a/packages/studio/src/components/AssetSelector.tsx b/packages/studio/src/components/AssetSelector.tsxindex 5f1af52985..90374eff92 100644--- a/packages/studio/src/components/AssetSelector.tsx+++ b/packages/studio/src/components/AssetSelector.tsx@@ -17,6 +17,7 @@ import {FolderContext} from '../state/folders';import {useZIndex} from '../state/z-index';import {AssetFolderTree} from './AssetSelectorItem';import {inlineCodeSnippet} from './Menu/styles';+import {showNotification} from './Notifications/NotificationCenter';import {handleUploadFile} from './utils';const container: React.CSSProperties = {@@ -54,7 +55,7 @@ type State = {};export const AssetSelector: React.FC<{- readOnlyStudio: boolean;+ readonly readOnlyStudio: boolean;}> = ({readOnlyStudio}) => {const {tabIndex} = useZIndex();const {assetFoldersExpanded, setAssetFoldersExpanded} =@@ -123,11 +124,26 @@ export const AssetSelector: React.FC<{);const onDrop: React.DragEventHandler<HTMLDivElement> = useCallback(- (e) => {- e.preventDefault();- e.stopPropagation();- handleUploadFile(e.dataTransfer.files[0], dropLocation || '/');- setDropLocation(null);+ async (e) => {+ try {+ e.preventDefault();+ e.stopPropagation();+ const {files} = e.dataTransfer;+ const assetPath = dropLocation || '/';+ for (const file of files) {+ await handleUploadFile(file, assetPath);+ }++ if (files.length === 1) {+ showNotification(`Added ${files[0].name} to ${assetPath}`, 3000);+ } else {+ showNotification(`Added ${files.length} files to ${assetPath}`, 3000);+ }++ setDropLocation(null);+ } catch (error) {+ showNotification(`Error during upload: ${error}`, 3000);+ }},[dropLocation],);diff --git a/packages/studio/src/components/utils.ts b/packages/studio/src/components/utils.tsindex 480c3770a7..93a5ee78ff 100644--- a/packages/studio/src/components/utils.ts+++ b/packages/studio/src/components/utils.ts@@ -1,30 +1,17 @@-import {showNotification} from './Notifications/NotificationCenter';-export const handleUploadFile = async (file: File, assetPath: string) => {- if (!file) {- showNotification('Please select a file first!', 3000);- return;- }-- try {- const url = new URL('/api/add-asset', window.location.origin);- url.search = new URLSearchParams({- folder: assetPath,- file: file.name,- }).toString();+ const url = new URL('/api/add-asset', window.location.origin);+ url.search = new URLSearchParams({+ folder: assetPath,+ file: file.name,+ }).toString();- const response = await fetch(url, {- method: 'POST',- body: file,- });+ const response = await fetch(url, {+ method: 'POST',+ body: file,+ });- if (response.ok) {- showNotification(`Added ${file.name} to ${assetPath}`, 3000);- } else {- const jsonResponse = await response.json();- showNotification(`Upload failed: ${jsonResponse.error}`, 3000);- }- } catch (error) {- showNotification(`Error during upload: ${error}`, 3000);+ if (!response.ok) {+ const jsonResponse = await response.json();+ throw new Error(jsonResponse.error);}};