Skip to content

Commit 0b62c8a

Browse files
Fixed bugs related to editting, added renaming
1 parent eb80eb0 commit 0b62c8a

File tree

8 files changed

+166
-63
lines changed

8 files changed

+166
-63
lines changed

src/main/main.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,26 +846,48 @@ ipcMain.handle('getPreviewImage', (event, { collectionId, game }) => {
846846
};
847847
});
848848

849+
ipcMain.handle(
850+
'renameVideo',
851+
(event, { id, newTitle, game }) => {
852+
log.info(
853+
`RENAMING ${id} to new title ${newTitle} for game ${game}`
854+
);
855+
856+
const {clip: videoFilePath, subtitle: subFilePath, thumbnail: thumbNailPath} = getClipPaths(id, game);
857+
const {clip: newVideoFilePath, subtitle: newSubFilePath, thumbnail: newThumbNailPath} = getClipPaths(newTitle.replaceAll(' ', '_'), game);
858+
859+
log.info(`RENAMING ${videoFilePath} to ${newVideoFilePath}`);
860+
fs.renameSync(videoFilePath, newVideoFilePath);
861+
862+
log.info(`RENAMING ${subFilePath} to ${newSubFilePath}`);
863+
fs.renameSync(subFilePath, newSubFilePath);
864+
865+
log.info(`RENAMING ${thumbNailPath} to ${newThumbNailPath}`);
866+
fs.renameSync(thumbNailPath, newThumbNailPath);
867+
}
868+
);
869+
849870
ipcMain.handle(
850871
'storeVideo',
851872
(event, { videoSource, subtitles, title, clipNumber, game }) => {
852873
log.info(
853-
`STORING ${title}-${clipNumber} for game ${game} with subtitles ${subtitles}`
874+
`STORING ${title}-${clipNumber} for game ${game} with subtitles \n${subtitles}`
854875
);
855876

856877
let id = createClipName(title, clipNumber);
857878
const {clip: videoFilePath, subtitle: subFilePath, thumbnail: thumbNailPath} = getClipPaths(id, game);
858879

859880
// Only store file if it's not already here.
860881
if (videoSource.startsWith("localfile://")) {
861-
log.info('SAVING TO ' + videoFilePath + '\n' + subFilePath);
882+
log.info('SAVING VIDEO TO ' + videoFilePath + '\n' + subFilePath);
862883
// Copy video file from where ever it was previously located.
863884
fs.copyFileSync(videoSource.replace("localfile://", ""), videoFilePath);
864885

865886
// Create a thumbnail
866887
const thumbnailTime = '00:00:01';
867888
createThumbnail(videoFilePath, thumbnailTime, thumbNailPath);
868889
}
890+
log.info('SAVING SUBS TO ' + subFilePath);
869891
fs.writeFileSync(subFilePath, subtitles);
870892

871893
return id;

src/main/preload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ contextBridge.exposeInMainWorld('api', {
2020
'storePreviewImage',
2121
'getVideos',
2222
'getVideo',
23+
'renameVideo',
2324
'storeVideo',
2425
'storeTempVideo',
2526
'deleteVideo',

src/renderer/components/ClipTable.jsx

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { useAtom } from 'jotai';
22
import React, { useState } from 'react';
33
import { Link } from 'react-router-dom';
4+
import { toast } from 'react-toastify';
45
import { gameAtom } from 'renderer/atoms/game.atom';
6+
import { interstitialAtom } from 'renderer/atoms/interstitial.atom';
7+
import { handleInterstitial } from 'renderer/components/interstitial/Interstitial';
58

69
export default ({
710
videos,
@@ -11,13 +14,47 @@ export default ({
1114
op,
1215
opFn,
1316
includeDelete,
17+
includeRename,
1418
onDelete,
19+
onRename,
1520
}) => {
1621
const [selectedCollection, setSelectedCollection] = useState(
1722
collectionId || ''
1823
);
1924
const [searchValue, setSearchValue] = useState(null);
25+
const [renaming, setRenaming] = useState(null);
26+
const [newTitle, setNewTitle] = useState(null);
2027
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+
};
2158

2259
let sortedVideos = Object.keys(collections).reduce((prev, curr) => {
2360
let collection = collections[curr];
@@ -119,15 +156,52 @@ export default ({
119156
src={`game://${game}/${video._id}.jpg`}
120157
/>
121158
</div>
122-
<div>{video._id.replace(/_/g, ' ')}</div>
123159
</div>
124160
</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}
125199
{includeDelete ? (
126200
<div>
127201
<button
128202
type="button"
129203
onClick={() => {
130-
onDelete(video._id, game);
204+
deleteClip(video._id, game);
131205
}}
132206
>
133207
Delete

src/renderer/components/SubtitleList.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default ({
3030
onSelectSub,
3131
onRemoveSub,
3232
onSave,
33+
isEdit,
3334
}) => {
3435
const [clipTitle, setClipTitle] = useState(titleOverride || '');
3536
const [clipNumber, setClipNumber] = useState(clipNumberOverride || 1);
@@ -75,6 +76,7 @@ export default ({
7576
onChange={({ target: { value } }) => {
7677
setClipTitle(value);
7778
}}
79+
disabled={isEdit}
7880
/>
7981
</td>
8082
</tr>
@@ -87,6 +89,7 @@ export default ({
8789
onChange={({ target: { value } }) => {
8890
setClipNumber(value);
8991
}}
92+
disabled={isEdit}
9093
/>
9194
</td>
9295
</tr>
@@ -98,6 +101,7 @@ export default ({
98101
onChange={({ target: { value } }) => {
99102
setSelectedCollection(value);
100103
}}
104+
disabled={isEdit}
101105
>
102106
<option key="_none">None</option>
103107
{Object.keys(collections).map(

src/renderer/components/WhatTheDubPlayer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default (props) => {
9292

9393
if (currentIndex >= 0) {
9494
let currentSubtitle = props.subs[currentIndex];
95-
if (currentSubtitle.type === 'dynamic') {
95+
if (currentSubtitle?.type === 'dynamic') {
9696
setMuted(false);
9797
}
9898
}

src/renderer/routes/VideoList.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@ let VideoList = () => {
114114
opFn={(collectionId, id) => {
115115
navigate(`/edit/${id}`);
116116
}}
117-
onDelete={(id, game) => {
118-
deleteFile(id, game);
117+
onDelete={() => {
118+
loadVideos();
119+
}}
120+
onRename={() => {
121+
loadVideos();
119122
}}
120123
includeDelete
124+
includeRename
121125
allowCollectionFilter
122126
/>
123127
</div>

0 commit comments

Comments
 (0)