@@ -9,14 +9,16 @@ import {
99 Button ,
1010 useDisclosure ,
1111 Input ,
12- Box
12+ Box ,
13+ Text
1314 } from "@chakra-ui/core" ;
1415import React , { useEffect , useState , useRef } from 'react' ;
1516import { client } from '../../api/djangoAPI' ;
1617
1718import VTTConverter from 'srt-webvtt' ;
1819
1920
21+
2022function SubtitleForm ( { video, token} ) {
2123
2224 const [ selectedFiles , setSelectedFiles ] = useState ( undefined ) ;
@@ -28,6 +30,13 @@ function SubtitleForm ({video, token}){
2830 hiddenFileInput . current . click ( ) ;
2931 } ;
3032
33+ function SendButton ( { isFileSelected} ) {
34+ if ( isFileSelected ) {
35+ return < Button onClick = { handleSubmit } > Send</ Button >
36+ }
37+ return < Button isDisabled = { true } onClick = { handleSubmit } > Send</ Button >
38+ }
39+
3140 const handleSubtitleChange = event => {
3241 let customsub = event . target . value ;
3342 var ext = customsub . substr ( customsub . lastIndexOf ( '.' ) + 1 ) ;
@@ -64,20 +73,15 @@ function SubtitleForm ({video, token}){
6473 } ;
6574
6675
67-
68- const handleSubtitleNameChange = event => {
69- setSubtitleName ( event . target . value ) ;
70- } ;
71-
72- const handleSubmit = async ( event ) => {
73- event . preventDefault ( )
74- //console.log("sending subtitle Language " + subtitleLanguage)
75- const response = await client . uploadSubtitles ( token . key , video . id , subtitleLanguage , selectedFiles [ 0 ] ) ;
76- //console.log('r', response)
77- if ( response . status != 201 )
78- alert ( "Something went wront, are you connected ?" ) ;
79- onClose ( ) ;
80- } ;
76+ const handleSubmit = async ( event ) => {
77+ event . preventDefault ( )
78+ //console.log("sending subtitle Language " + subtitleLanguage)
79+ const response = await client . uploadSubtitles ( token . key , video . id , subtitleLanguage , selectedFiles [ 0 ] ) ;
80+ //console.log('r', response)
81+ if ( response . status != 201 )
82+ alert ( "Something went wront, are you connected ?" ) ;
83+ onClose ( ) ;
84+ } ;
8185
8286 const handleResync = async ( videoid , subid ) => {
8387 console . log ( videoid ) ;
@@ -89,47 +93,57 @@ function SubtitleForm ({video, token}){
8993 const { isOpen, onOpen, onClose } = useDisclosure ( ) ;
9094
9195 return (
92-
93- < >
94- < Button onClick = { onOpen } > Handle subtitles</ Button >
95-
96- < Modal isOpen = { isOpen } onClose = { onClose } onS isCentered >
97- < ModalOverlay />
98- < ModalContent >
99- < ModalHeader color = "black" > Add Custom subtitles:</ ModalHeader >
100- < ModalCloseButton />
101- < ModalBody mt = { 4 } >
102- < Box m = { 4 } >
103-
104- < Button mb = { 4 } onClick = { handleClick } > Upload SUB </ Button >
105- < Input type = "file"
106- onChange = { handleSubtitleChange }
107- accept = ".srt"
108- ref = { hiddenFileInput }
109- style = { { display :'none' } }
96+ < >
97+ < Button onClick = { onOpen } > Handle subtitles</ Button >
98+
99+ < Modal isOpen = { isOpen } onClose = { onClose } onS isCentered >
100+ < ModalOverlay />
101+ < ModalContent >
102+ < ModalHeader color = "black" > Subtitles menu</ ModalHeader >
103+ < ModalCloseButton />
104+ < ModalBody >
105+ < Box mb = { 4 } >
106+ < Text color = "black" > Upload your subtitles:</ Text >
107+ < Button onClick = { handleClick } >
108+ Upload SUB{ " " }
109+ </ Button >
110+ < Input
111+ type = "file"
112+ onChange = { handleSubtitleChange }
113+ accept = ".srt"
114+ ref = { hiddenFileInput }
115+ style = { { display : "none" } }
110116 />
111- < Input mb = { 4 } type = "text" defaultValue = "Custom Subtitle" value = { subtitleName } onChange = { handleSubtitleNameChange } />
112117 < select onChange = { handleSubtitleLangChange } >
113118 < option value = "fra" > French</ option >
114- < option selected value = "eng" > English</ option >
119+ < option selected value = "eng" >
120+ English
121+ </ option >
115122 </ select >
116- </ Box >
117- < ModalHeader color = "black" > Resync existing subtitle:</ ModalHeader >
118- { ! video . subtitles ? null : video . subtitles . map ( sub =>
119- < Button mb = { 4 } onClick = { handleResync . bind ( this , video . id , sub . id ) } > { sub . language } </ Button > ) }
120- </ ModalBody >
121-
122- < ModalFooter >
123- < Button mb = { 4 } onClick = { handleSubmit } mr = { 3 } > Send</ Button >
124- < Button variantColor = "blue" onClick = { onClose } >
125- Close
126- </ Button >
127- </ ModalFooter >
128- </ ModalContent >
129- </ Modal >
130- </ >
131-
132- )
123+
124+ < SendButton isFileSelected = { selectedFiles } > </ SendButton >
125+ < Text mt = { 4 } color = "black" > Resync existing subtitles:</ Text >
126+ { ! video . subtitles
127+ ? null
128+ : video . subtitles . map ( ( sub ) => (
129+ < Button
130+ onClick = { handleResync . bind ( this , video . id , sub . id ) }
131+ >
132+ { sub . language } { " " }
133+ </ Button >
134+ ) ) }
135+ </ Box >
136+ </ ModalBody >
137+
138+ < ModalFooter >
139+ < Button onClick = { onClose } >
140+ Close
141+ </ Button >
142+ </ ModalFooter >
143+ </ ModalContent >
144+ </ Modal >
145+ </ >
146+ ) ;
133147}
134148
135149export default SubtitleForm ;
0 commit comments