diff --git a/src/main/main.ts b/src/main/main.ts index f6f31ec..3555d74 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -192,6 +192,10 @@ const addToCollection = ( collectionId: string, videoIdList: Array ) => { + log.info( + `ADDING ${videoIdList} for game ${game} to collection ${collectionId}` + ); + // If the collection isn't present, create a key and an empty array for it. if (!(collectionId in collections[game])) { collections[game][collectionId] = []; @@ -204,6 +208,10 @@ const addToCollection = ( } }); + const collection = collections[game][collectionId]; + collection.sort(); + collections[game][collectionId] = collection; + const {collectionMeta} = getConfigDirectories(); log.info("WRITING TO " + collectionMeta); @@ -213,6 +221,35 @@ const addToCollection = ( return collections[game]; }; +const removeFromCollection = (game: string, collectionId: string, videoId: string) => { + log.info( + `REMOVING ${videoId} for game ${game} from collection ${collectionId}` + ); + + // If the collection isn't present, return immediately. + if (!(collectionId in collections[game])) { + log.info("COLLECTION NOT PRESENT"); + return; + } + + // Filter out videoId that's being removed. + collections[game][collectionId] = collections[game][collectionId].filter( + (element: string) => element !== videoId + ); + + const collection = collections[game][collectionId]; + collection.sort(); + collections[game][collectionId] = collection; + + const {collectionMeta} = getConfigDirectories(); + + // Store updated file + fs.writeFileSync( + collectionMeta, + JSON.stringify(collections, null, 5) + ); +} + const importZip = async (filePath: string, game: string) => { // Extract video names from zip const zip = new StreamZip.async({ file: filePath }); @@ -848,13 +885,15 @@ ipcMain.handle('getPreviewImage', (event, { collectionId, game }) => { ipcMain.handle( 'renameVideo', - (event, { id, newTitle, game }) => { + (event, { id, newTitle, game, collectionId }) => { log.info( - `RENAMING ${id} to new title ${newTitle} for game ${game}` + `RENAMING ${id} to new title ${newTitle} in collection ${collectionId} for game ${game}` ); + const newId = newTitle.replaceAll(' ', '_'); + const {clip: videoFilePath, subtitle: subFilePath, thumbnail: thumbNailPath} = getClipPaths(id, game); - const {clip: newVideoFilePath, subtitle: newSubFilePath, thumbnail: newThumbNailPath} = getClipPaths(newTitle.replaceAll(' ', '_'), game); + const {clip: newVideoFilePath, subtitle: newSubFilePath, thumbnail: newThumbNailPath} = getClipPaths(newId, game); log.info(`RENAMING ${videoFilePath} to ${newVideoFilePath}`); fs.renameSync(videoFilePath, newVideoFilePath); @@ -864,6 +903,9 @@ ipcMain.handle( log.info(`RENAMING ${thumbNailPath} to ${newThumbNailPath}`); fs.renameSync(thumbNailPath, newThumbNailPath); + + removeFromCollection(game, collectionId, id); + addToCollection(game, collectionId, [newId]); } ); @@ -988,6 +1030,10 @@ ipcMain.handle('addToCollection', (event, { collectionId, videoId, game }) => { collections[game][collectionId].push(videoId); } + const collection = collections[game][collectionId]; + collection.sort(); + collections[game][collectionId] = collection; + const {collectionMeta} = getConfigDirectories(); // Store updated file @@ -1013,6 +1059,10 @@ ipcMain.handle( (element: string) => element !== videoId ); + const collection = collections[game][collectionId]; + collection.sort(); + collections[game][collectionId] = collection; + const {collectionMeta} = getConfigDirectories(); // Store updated file diff --git a/src/renderer/components/ClipTable.jsx b/src/renderer/components/ClipTable.jsx index 9422016..0bcc7f0 100644 --- a/src/renderer/components/ClipTable.jsx +++ b/src/renderer/components/ClipTable.jsx @@ -28,9 +28,17 @@ export default ({ const [, setInterstitialState] = useAtom(interstitialAtom); const renameClip = async () => { - console.log('RENAMED'); + const collectionId = Object.keys(collections).find((key) => + collections[key].includes(renaming) + ); + await handleInterstitial( - window.api.send('renameVideo', { id: renaming, game, newTitle }), + window.api.send('renameVideo', { + id: renaming, + game, + newTitle, + collectionId, + }), (open) => { setInterstitialState(open); } @@ -170,34 +178,37 @@ export default ({ /> )} - {includeRename ? ( -
- {renaming !== video._id ? ( - - ) : ( - - )} -
- ) : null} - {includeDelete ? ( -
+
+ {includeRename ? ( + <> + {renaming !== video._id ? ( + + ) : ( + + )} + + ) : null} + {includeDelete ? ( -
- ) : null} + ) : null} +
); })} diff --git a/src/renderer/routes/VideoList.jsx b/src/renderer/routes/VideoList.jsx index 8ff871e..ac1402e 100644 --- a/src/renderer/routes/VideoList.jsx +++ b/src/renderer/routes/VideoList.jsx @@ -62,17 +62,6 @@ let VideoList = () => { return Loading Media

} />; } - const deleteFile = async (id, game, isActive) => { - await handleInterstitial( - window.api.send('deleteVideo', { id, game, isActive }), - (open) => { - setInterstitialState(open); - } - ); - toast('Deleted video', { type: 'info' }); - loadVideos(); - }; - let sortedVideos = Object.keys(collections).reduce((prev, curr) => { let collection = collections[curr]; collection.forEach((video) => {