diff --git a/apps/website/src/components/Playground/Workspace/Editor.tsx b/apps/website/src/components/Playground/Workspace/Editor.tsx index 46ea1e31437..e2df898bd8f 100644 --- a/apps/website/src/components/Playground/Workspace/Editor.tsx +++ b/apps/website/src/components/Playground/Workspace/Editor.tsx @@ -57,7 +57,7 @@ export default function Editor({ - Editor: + Editor Edit arguments below to update command: - File System: + File System: arg === "-i"); + if (inputFlagIdx !== -1 && inputFlagIdx < argsArray.length - 1) { + return inputFlagIdx + 1; + } + } catch (e) { + // Invalid JSON, return -1 + } + return -1; +} + interface WorkspaceProps { ffmpeg: MutableRefObject; } export default function Workspace({ ffmpeg: _ffmpeg }: WorkspaceProps) { + const theme = useTheme(); + const isSmallScreen = useMediaQuery(theme.breakpoints.down("md")); + + const [accordionExpanded, setAccordionExpanded] = useState(false); const [path, setPath] = useState("/"); const [nodes, setNodes] = useState([]); const [oldName, setOldName] = useState(""); @@ -32,6 +58,10 @@ export default function Workspace({ ffmpeg: _ffmpeg }: WorkspaceProps) { const [logs, setLogs] = useState([]); const ffmpeg = _ffmpeg.current; + + useEffect(() => { + setAccordionExpanded(!isSmallScreen); + }, [isSmallScreen]); const refreshDir = async (curPath: string) => { if (ffmpeg.loaded) { @@ -52,13 +82,25 @@ export default function Workspace({ ffmpeg: _ffmpeg }: WorkspaceProps) { const onFileUpload = (isText: boolean) => async ({ target: { files } }: ChangeEvent) => { + let lastFileName = ""; for (let i = 0; i < files.length; i++) { const file = files[i]; let data: Uint8Array | string = await fetchFile(file); if (isText) data = new TextDecoder().decode(data); await ffmpeg.writeFile(`${path}/${file.name}`, data); + lastFileName = file.name; + } + // Update args JSON to use the uploaded filename + if (!isText && lastFileName) { + const inputPathIdx = findInputPathIdx(args); + if (inputPathIdx !== -1) { + const argsArray = JSON.parse(args); + argsArray[inputPathIdx] = lastFileName; + setArgs(JSON.stringify(argsArray, null, 2)); + } } refreshDir(path); + setAccordionExpanded(true); }; const onFileClick = (name: string) => async (option: string) => { @@ -122,6 +164,7 @@ export default function Workspace({ ffmpeg: _ffmpeg }: WorkspaceProps) { await ffmpeg.writeFile(name, await fetchFile(SAMPLE_FILES[name])); } refreshDir(path); + setAccordionExpanded(true); }; const onExec = async () => { @@ -151,22 +194,65 @@ export default function Workspace({ ffmpeg: _ffmpeg }: WorkspaceProps) { - refreshDir(path)} - /> + + + or + + + setAccordionExpanded(isExpanded)} + > + } + aria-controls="file-system-content" + id="file-system-header" + > + File System + + + refreshDir(path)} + /> + + Load Sample Files to download & add sample files. +2. Upload your own files, or press Load Sample Files to download & add sample files. 3. Press Run to convert an AVI file to MP4 file. -4. Download output files. +4. Click the three-dots menu next to a file in the File Explorer to download output files. ::: @@ -96,7 +96,7 @@ System to make sure these files can be consumed by the ffmpeg.wasm APIs: > Press Load Sample Files to load a set of samples files. -#### Run a command +#### Run a command With files are ready in the File System, you can update arguments in the Editor and hit Run afterward: