1
- import React , { useState } from 'react' ;
2
- import { useParams , useNavigate } from 'react-router' ;
1
+ import React , { useState } from 'react' ;
2
+ import { useParams , useNavigate } from 'react-router' ;
3
3
import { Link } from 'react-router-dom' ;
4
- import { toast } from 'react-toastify' ;
5
- import { addVideo } from '../util/VideoTools' ;
4
+ import { toast } from 'react-toastify' ;
5
+ import { addVideo } from '../ ../util/VideoTools' ;
6
6
7
- import { api } from '../util/Api' ;
7
+ import { api } from '../ ../util/Api' ;
8
8
9
- import WhatTheDubPlayer from '../components/WhatTheDubPlayer' ;
10
- import TimeLine from '../components/TimeLine' ;
11
- import SubtitleList from '../components/SubtitleList' ;
9
+ import WhatTheDubPlayer from '../../components/WhatTheDubPlayer' ;
10
+ import TimeLine from '../../components/TimeLine' ;
11
+ import SubtitleList from '../../components/SubtitleList' ;
12
+ import CollectionAPI from 'api/CollectionAPI' ;
12
13
13
14
let AdvancedEditor = ( ) => {
14
15
const params = useParams ( ) ;
15
16
const navigate = useNavigate ( ) ;
16
17
17
- const [ windowSize , setWindowSize ] = useState ( { width : window . innerWidth , height : window . innerHeight } ) ;
18
+ const [ windowSize , setWindowSize ] = useState ( { width : window . innerWidth , height : window . innerHeight } ) ;
18
19
19
20
const [ error , setError ] = useState ( null ) ;
20
21
const [ videoSource , setVideoSource ] = useState ( "" ) ;
@@ -37,7 +38,7 @@ let AdvancedEditor = () => {
37
38
}
38
39
39
40
window . onresize = ( ) => {
40
- setWindowSize ( { width : window . innerWidth , height : window . innerHeight } )
41
+ setWindowSize ( { width : window . innerWidth , height : window . innerHeight } )
41
42
}
42
43
43
44
let onFileOpen = ( e ) => {
@@ -65,12 +66,12 @@ let AdvancedEditor = () => {
65
66
} else if ( seconds > videoLength * 1000 ) {
66
67
seconds = videoLength * 1000 ;
67
68
}
68
- setCurrentPosition ( seconds / 1000 ) ;
69
+ setCurrentPosition ( seconds / 1000 ) ;
69
70
setCurrentSliderPosition ( seconds ) ;
70
71
setIsPlaying ( false ) ;
71
72
}
72
73
73
- let addVideoToGame = async ( videoName , clipNumber ) => {
74
+ let addVideoToGame = async ( videoName , clipNumber , collectionId ) => {
74
75
if ( await checkClipExists ( videoName , clipNumber ) ) {
75
76
setError ( "Clip with this name and number already exists" ) ;
76
77
return ;
@@ -80,19 +81,22 @@ let AdvancedEditor = () => {
80
81
81
82
try {
82
83
setButtonsDisabled ( true ) ;
83
- await addVideo ( videoSource . substring ( videoSource . indexOf ( ',' ) + 1 ) , subs , videoName , clipNumber , params . type ) ;
84
+ let videoId = await addVideo ( videoSource . substring ( videoSource . indexOf ( ',' ) + 1 ) , subs , videoName , clipNumber , params . type ) ;
85
+ if ( ! collectionId . startsWith ( "_" ) ) {
86
+ await CollectionAPI . addToCollection ( collectionId , params . type , videoId ) ;
87
+ }
84
88
setButtonsDisabled ( false ) ;
85
89
86
- toast ( `Clip added successfully!` , { type : "info" } ) ;
90
+ toast ( `Clip added successfully!` , { type : "info" } ) ;
87
91
navigate ( '/' ) ;
88
92
} catch ( error ) {
89
93
console . error ( error ) ;
90
- toast ( `Clip add failed!` , { type : "error" } ) ;
94
+ toast ( `Clip add failed!` , { type : "error" } ) ;
91
95
}
92
96
}
93
97
94
98
let checkClipExists = async ( title , clipNumber ) => {
95
- return await api . send ( "clipExists" , { title, clipNumber, game : params . type } ) ;
99
+ return await api . send ( "clipExists" , { title, clipNumber, game : params . type } ) ;
96
100
}
97
101
98
102
const subChangeHandler = ( mode , sub ) => {
@@ -152,8 +156,8 @@ let AdvancedEditor = () => {
152
156
153
157
return (
154
158
< div >
155
- < div style = { { color : "red" } } > { error } </ div >
156
- { videoSource ?
159
+ < div style = { { color : "red" } } > { error } </ div >
160
+ { videoSource ?
157
161
< div className = "editor-container" >
158
162
< div className = "top-pane" >
159
163
< WhatTheDubPlayer
@@ -181,7 +185,7 @@ let AdvancedEditor = () => {
181
185
subs = { subs }
182
186
onSubsChange = { subChangeHandler }
183
187
onSelectSub = { setCurrentSub }
184
- onSave = { ( title , number ) => { addVideoToGame ( title , number ) } } />
188
+ onSave = { ( title , number , collectionId ) => { addVideoToGame ( title , number , collectionId ) } } />
185
189
</ div >
186
190
< TimeLine
187
191
timelineWidth = { windowSize . width * 0.9 }
0 commit comments