Skip to content

Commit d9a5ace

Browse files
committed
ensure that you see init errors
1 parent 56ae046 commit d9a5ace

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

pages/index.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import classNames from "classnames";
12
import Head from "next/head";
23
import Router, {useRouter} from "next/router";
34
import {useContext, useEffect, useState} from "react";
@@ -17,10 +18,11 @@ const DEMO_IMAGES = [...Array(28)].map((_, i) => `/demo/${(i + 1).toString().pad
1718
export default function Start() {
1819
const [video, setVideo] = useContext(VideoContext);
1920
const [demoCrop, setDemoCrop] = useState<Crop>({start: DEMO_TIMELINE.start, duration: DEMO_TIMELINE.duration * 0.75});
21+
const [error, setError] = useState<string | undefined>();
2022
const {pathname} = useRouter();
2123

2224
useEffect(() => {
23-
ensureFreshFfmpegInstance();
25+
ensureFreshFfmpegInstance().catch(e => setError(String(e)));
2426
Router.prefetch("/video").catch(console.error);
2527
}, []);
2628

@@ -56,9 +58,12 @@ export default function Start() {
5658
</h1>
5759
<div className="text-center motion-safe:animate-fly-2">
5860
<Markdown>{t('upload.description')}</Markdown>
59-
<input type="file" id="file" accept="video/*" onChange={e => setVideo(e.currentTarget.files?.[0], 'selected')} className="sr-only peer"/>
60-
<label htmlFor="file" className="inline-block relative px-5 py-3 text-2xl rounded-3xl bg-red-900 hover:bg-red-800 shadow-lg shadow-red-900/30 text-white text-xl cursor-pointer peer-focus:ring">
61-
<div className="absolute inset-0 rounded-3xl bg-red-900/20 animate-ping pointer-events-none"/>
61+
<input type="file" id="file" accept="video/*" disabled={!!error} onChange={e => setVideo(e.currentTarget.files?.[0], 'selected')} className="sr-only peer"/>
62+
<label htmlFor="file" className={classNames(
63+
'inline-block relative px-5 py-3 text-2xl rounded-3xl bg-red-900 hover:bg-red-800 shadow-lg shadow-red-900/30 text-white text-xl cursor-pointer peer-focus:ring',
64+
{'opacity-50 cursor-not-allowed': !!error},
65+
)}>
66+
{!error && <div className="absolute inset-0 rounded-3xl bg-red-900/20 animate-ping pointer-events-none"/>}
6267
<div className="relative">
6368
<AddFileIcon className="align-text-bottom mr-2 -ml-1"/>
6469
{t('upload.button')}
@@ -67,9 +72,14 @@ export default function Start() {
6772
</span>
6873
</div>
6974
</label>
70-
<p className="my-4 text-red-200 whitespace-pre-wrap">
71-
{t('upload.disclaimer')}
72-
</p>
75+
{error
76+
? <p className="my-4 h-min-3l whitespace-pre-wrap">
77+
{error}
78+
</p>
79+
: <p className="my-4 h-min-3l text-red-200 whitespace-pre-wrap">
80+
{t('upload.disclaimer')}
81+
</p>
82+
}
7383
</div>
7484
</div>
7585

src/ffmpeg.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export function ensureFreshFfmpegInstance () {
5959
lastInputFile = undefined;
6060
running = false;
6161
}
62+
63+
return instancePromise;
6264
}
6365

6466
async function createInstance() {

0 commit comments

Comments
 (0)