1
+ import classNames from "classnames" ;
1
2
import Head from "next/head" ;
2
3
import Router , { useRouter } from "next/router" ;
3
4
import { useContext , useEffect , useState } from "react" ;
@@ -17,10 +18,11 @@ const DEMO_IMAGES = [...Array(28)].map((_, i) => `/demo/${(i + 1).toString().pad
17
18
export default function Start ( ) {
18
19
const [ video , setVideo ] = useContext ( VideoContext ) ;
19
20
const [ demoCrop , setDemoCrop ] = useState < Crop > ( { start : DEMO_TIMELINE . start , duration : DEMO_TIMELINE . duration * 0.75 } ) ;
21
+ const [ error , setError ] = useState < string | undefined > ( ) ;
20
22
const { pathname} = useRouter ( ) ;
21
23
22
24
useEffect ( ( ) => {
23
- ensureFreshFfmpegInstance ( ) ;
25
+ ensureFreshFfmpegInstance ( ) . catch ( e => setError ( String ( e ) ) ) ;
24
26
Router . prefetch ( "/video" ) . catch ( console . error ) ;
25
27
} , [ ] ) ;
26
28
@@ -56,9 +58,12 @@ export default function Start() {
56
58
</ h1 >
57
59
< div className = "text-center motion-safe:animate-fly-2" >
58
60
< 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" /> }
62
67
< div className = "relative" >
63
68
< AddFileIcon className = "align-text-bottom mr-2 -ml-1" />
64
69
{ t ( 'upload.button' ) }
@@ -67,9 +72,14 @@ export default function Start() {
67
72
</ span >
68
73
</ div >
69
74
</ 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
+ }
73
83
</ div >
74
84
</ div >
75
85
0 commit comments