1
1
import { useAtom } from 'jotai' ;
2
2
import React , { useState } from 'react' ;
3
3
import { Link } from 'react-router-dom' ;
4
+ import { toast } from 'react-toastify' ;
4
5
import { gameAtom } from 'renderer/atoms/game.atom' ;
6
+ import { interstitialAtom } from 'renderer/atoms/interstitial.atom' ;
7
+ import { handleInterstitial } from 'renderer/components/interstitial/Interstitial' ;
5
8
6
9
export default ( {
7
10
videos,
@@ -11,13 +14,47 @@ export default ({
11
14
op,
12
15
opFn,
13
16
includeDelete,
17
+ includeRename,
14
18
onDelete,
19
+ onRename,
15
20
} ) => {
16
21
const [ selectedCollection , setSelectedCollection ] = useState (
17
22
collectionId || ''
18
23
) ;
19
24
const [ searchValue , setSearchValue ] = useState ( null ) ;
25
+ const [ renaming , setRenaming ] = useState ( null ) ;
26
+ const [ newTitle , setNewTitle ] = useState ( null ) ;
20
27
const [ game , setGame ] = useAtom ( gameAtom ) ;
28
+ const [ , setInterstitialState ] = useAtom ( interstitialAtom ) ;
29
+
30
+ const renameClip = async ( ) => {
31
+ console . log ( 'RENAMED' ) ;
32
+ await handleInterstitial (
33
+ window . api . send ( 'renameVideo' , { id : renaming , game, newTitle } ) ,
34
+ ( open ) => {
35
+ setInterstitialState ( open ) ;
36
+ }
37
+ ) ;
38
+ toast ( 'Renamed video' , { type : 'info' } ) ;
39
+
40
+ if ( onRename ) {
41
+ onRename ( ) ;
42
+ }
43
+ } ;
44
+
45
+ const deleteClip = async ( id , game , isActive ) => {
46
+ await handleInterstitial (
47
+ window . api . send ( 'deleteVideo' , { id, game, isActive } ) ,
48
+ ( open ) => {
49
+ setInterstitialState ( open ) ;
50
+ }
51
+ ) ;
52
+ toast ( 'Deleted video' , { type : 'info' } ) ;
53
+
54
+ if ( onDelete ) {
55
+ onDelete ( ) ;
56
+ }
57
+ } ;
21
58
22
59
let sortedVideos = Object . keys ( collections ) . reduce ( ( prev , curr ) => {
23
60
let collection = collections [ curr ] ;
@@ -119,15 +156,52 @@ export default ({
119
156
src = { `game://${ game } /${ video . _id } .jpg` }
120
157
/>
121
158
</ div >
122
- < div > { video . _id . replace ( / _ / g, ' ' ) } </ div >
123
159
</ div >
124
160
</ div >
161
+ { renaming !== video . _id ? (
162
+ < div > { video . _id . replace ( / _ / g, ' ' ) } </ div >
163
+ ) : (
164
+ < div >
165
+ < input
166
+ value = { newTitle }
167
+ onChange = { ( { target : { value } } ) => {
168
+ setNewTitle ( value ) ;
169
+ } }
170
+ />
171
+ </ div >
172
+ ) }
173
+ { includeRename ? (
174
+ < div >
175
+ { renaming !== video . _id ? (
176
+ < button
177
+ type = "button"
178
+ onClick = { ( ) => {
179
+ setNewTitle (
180
+ video . _id . replace ( / _ / g, ' ' )
181
+ ) ;
182
+ setRenaming ( video . _id ) ;
183
+ } }
184
+ >
185
+ Rename
186
+ </ button >
187
+ ) : (
188
+ < button
189
+ onClick = { ( ) => {
190
+ renameClip ( ) ;
191
+ setRenaming ( null ) ;
192
+ } }
193
+ >
194
+ Done
195
+ </ button >
196
+ ) }
197
+ </ div >
198
+ ) : null }
125
199
{ includeDelete ? (
126
200
< div >
127
201
< button
128
202
type = "button"
129
203
onClick = { ( ) => {
130
- onDelete ( video . _id , game ) ;
204
+ deleteClip ( video . _id , game ) ;
131
205
} }
132
206
>
133
207
Delete
0 commit comments