Skip to content

Commit

Permalink
Fixed bugs related to editting, added renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
deusprogrammer committed Nov 5, 2023
1 parent eb80eb0 commit 0b62c8a
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 63 deletions.
26 changes: 24 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,26 +846,48 @@ ipcMain.handle('getPreviewImage', (event, { collectionId, game }) => {
};
});

ipcMain.handle(
'renameVideo',
(event, { id, newTitle, game }) => {
log.info(
`RENAMING ${id} to new title ${newTitle} for game ${game}`
);

const {clip: videoFilePath, subtitle: subFilePath, thumbnail: thumbNailPath} = getClipPaths(id, game);
const {clip: newVideoFilePath, subtitle: newSubFilePath, thumbnail: newThumbNailPath} = getClipPaths(newTitle.replaceAll(' ', '_'), game);

log.info(`RENAMING ${videoFilePath} to ${newVideoFilePath}`);
fs.renameSync(videoFilePath, newVideoFilePath);

log.info(`RENAMING ${subFilePath} to ${newSubFilePath}`);
fs.renameSync(subFilePath, newSubFilePath);

log.info(`RENAMING ${thumbNailPath} to ${newThumbNailPath}`);
fs.renameSync(thumbNailPath, newThumbNailPath);
}
);

ipcMain.handle(
'storeVideo',
(event, { videoSource, subtitles, title, clipNumber, game }) => {
log.info(
`STORING ${title}-${clipNumber} for game ${game} with subtitles ${subtitles}`
`STORING ${title}-${clipNumber} for game ${game} with subtitles \n${subtitles}`
);

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

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

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

return id;
Expand Down
1 change: 1 addition & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contextBridge.exposeInMainWorld('api', {
'storePreviewImage',
'getVideos',
'getVideo',
'renameVideo',
'storeVideo',
'storeTempVideo',
'deleteVideo',
Expand Down
78 changes: 76 additions & 2 deletions src/renderer/components/ClipTable.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useAtom } from 'jotai';
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import { toast } from 'react-toastify';
import { gameAtom } from 'renderer/atoms/game.atom';
import { interstitialAtom } from 'renderer/atoms/interstitial.atom';
import { handleInterstitial } from 'renderer/components/interstitial/Interstitial';

export default ({
videos,
Expand All @@ -11,13 +14,47 @@ export default ({
op,
opFn,
includeDelete,
includeRename,
onDelete,
onRename,
}) => {
const [selectedCollection, setSelectedCollection] = useState(
collectionId || ''
);
const [searchValue, setSearchValue] = useState(null);
const [renaming, setRenaming] = useState(null);
const [newTitle, setNewTitle] = useState(null);
const [game, setGame] = useAtom(gameAtom);
const [, setInterstitialState] = useAtom(interstitialAtom);

const renameClip = async () => {
console.log('RENAMED');
await handleInterstitial(
window.api.send('renameVideo', { id: renaming, game, newTitle }),
(open) => {
setInterstitialState(open);
}
);
toast('Renamed video', { type: 'info' });

if (onRename) {
onRename();
}
};

const deleteClip = async (id, game, isActive) => {
await handleInterstitial(
window.api.send('deleteVideo', { id, game, isActive }),
(open) => {
setInterstitialState(open);
}
);
toast('Deleted video', { type: 'info' });

if (onDelete) {
onDelete();
}
};

let sortedVideos = Object.keys(collections).reduce((prev, curr) => {
let collection = collections[curr];
Expand Down Expand Up @@ -119,15 +156,52 @@ export default ({
src={`game://${game}/${video._id}.jpg`}
/>
</div>
<div>{video._id.replace(/_/g, ' ')}</div>
</div>
</div>
{renaming !== video._id ? (
<div>{video._id.replace(/_/g, ' ')}</div>
) : (
<div>
<input
value={newTitle}
onChange={({ target: { value } }) => {
setNewTitle(value);
}}
/>
</div>
)}
{includeRename ? (
<div>
{renaming !== video._id ? (
<button
type="button"
onClick={() => {
setNewTitle(
video._id.replace(/_/g, ' ')
);
setRenaming(video._id);
}}
>
Rename
</button>
) : (
<button
onClick={() => {
renameClip();
setRenaming(null);
}}
>
Done
</button>
)}
</div>
) : null}
{includeDelete ? (
<div>
<button
type="button"
onClick={() => {
onDelete(video._id, game);
deleteClip(video._id, game);
}}
>
Delete
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/components/SubtitleList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default ({
onSelectSub,
onRemoveSub,
onSave,
isEdit,
}) => {
const [clipTitle, setClipTitle] = useState(titleOverride || '');
const [clipNumber, setClipNumber] = useState(clipNumberOverride || 1);
Expand Down Expand Up @@ -75,6 +76,7 @@ export default ({
onChange={({ target: { value } }) => {
setClipTitle(value);
}}
disabled={isEdit}
/>
</td>
</tr>
Expand All @@ -87,6 +89,7 @@ export default ({
onChange={({ target: { value } }) => {
setClipNumber(value);
}}
disabled={isEdit}
/>
</td>
</tr>
Expand All @@ -98,6 +101,7 @@ export default ({
onChange={({ target: { value } }) => {
setSelectedCollection(value);
}}
disabled={isEdit}
>
<option key="_none">None</option>
{Object.keys(collections).map(
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/WhatTheDubPlayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default (props) => {

if (currentIndex >= 0) {
let currentSubtitle = props.subs[currentIndex];
if (currentSubtitle.type === 'dynamic') {
if (currentSubtitle?.type === 'dynamic') {
setMuted(false);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/routes/VideoList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ let VideoList = () => {
opFn={(collectionId, id) => {
navigate(`/edit/${id}`);
}}
onDelete={(id, game) => {
deleteFile(id, game);
onDelete={() => {
loadVideos();
}}
onRename={() => {
loadVideos();
}}
includeDelete
includeRename
allowCollectionFilter
/>
</div>
Expand Down
Loading

0 comments on commit 0b62c8a

Please sign in to comment.