Skip to content

Commit

Permalink
Updated keyboard controls and turned clip table into a component:
Browse files Browse the repository at this point in the history
  • Loading branch information
deusprogrammer committed Nov 3, 2023
1 parent c7cc46b commit 379cdc6
Show file tree
Hide file tree
Showing 9 changed files with 451 additions and 248 deletions.
3 changes: 3 additions & 0 deletions src/renderer/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ button.selected {
.subtitle-list {
max-height: 200px;
overflow-y: scroll;
}

.subtitle-list table {
margin: auto;
}

Expand Down
102 changes: 52 additions & 50 deletions src/renderer/components/ClipList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,56 +63,58 @@ export default ({
</Link>
</div>
<h3>Clips</h3>
<table className="subtitle-list">
<thead>
<tr>
<th>Index</th>
<th>In</th>
<th>Out</th>
<th></th>
</tr>
</thead>
<tbody>
{clips.map((clip) => {
return (
<tr
className={
clip.index === currentClip
? 'selected'
: null
}
style={{ cursor: 'pointer' }}
onClick={() => {
onSelectClip(clip.index);
}}
>
<td>[{clip.index}]</td>
<td>
{convertMillisecondsToTimestamp(
clip.startTime
)}
</td>
<td>
{convertMillisecondsToTimestamp(
clip.endTime
)}
</td>
<td>
<button
onClick={(e) => {
onClipsChange('remove', clip);
onSelectClip(null);
e.stopPropagation();
}}
>
Remove
</button>
</td>
</tr>
);
})}
</tbody>
</table>
<div className="subtitle-list">
<table>
<thead>
<tr>
<th>Index</th>
<th>In</th>
<th>Out</th>
<th></th>
</tr>
</thead>
<tbody>
{clips.map((clip) => {
return (
<tr
className={
clip.index === currentClip
? 'selected'
: null
}
style={{ cursor: 'pointer' }}
onClick={() => {
onSelectClip(clip.index);
}}
>
<td>[{clip.index}]</td>
<td>
{convertMillisecondsToTimestamp(
clip.startTime
)}
</td>
<td>
{convertMillisecondsToTimestamp(
clip.endTime
)}
</td>
<td>
<button
onClick={(e) => {
onClipsChange('remove', clip);
onSelectClip(null);
e.stopPropagation();
}}
>
Remove
</button>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
<button
onClick={() => {
onClipsChange('add', {
Expand Down
129 changes: 129 additions & 0 deletions src/renderer/components/ClipTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { useAtom } from 'jotai';
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import { gameAtom } from 'renderer/atoms/game.atom';

export default ({
videos,
collections,
collectionId,
op,
opFn,
includeDelete,
onDelete,
}) => {
const [selectedCollection, setSelectedCollection] = useState(
collectionId || ''
);
const [searchValue, setSearchValue] = useState(null);
const [game, setGame] = useAtom(gameAtom);

let sortedVideos = Object.keys(collections).reduce((prev, curr) => {
let collection = collections[curr];
collection.forEach((video) => {
if (prev && !prev.includes(video)) {
prev.push(video);
}
});
return prev;
}, []);

let unsortedVideos = videos.filter((video) => {
return !sortedVideos.includes(video._id) && video._id.startsWith('_');
});

if (selectedCollection === 'unsorted') {
videos = unsortedVideos;
} else {
videos = videos.filter(({ _id, name }) => {
let f = true;
if (collections[selectedCollection]) {
f = f && collections[selectedCollection].includes(_id);
}
if (searchValue) {
f = f && name.toLowerCase().includes(searchValue.toLowerCase());
}

return f;
});
}

return (
<div>
<div>
<label>Search:</label>
<input
type="text"
onChange={({ target: { value } }) => {
setSearchValue(value);
}}
/>
{!collectionId ? (
<>
<label>Clip Pack:</label>
<select
onChange={({ target: { value } }) => {
setSelectedCollection(value);
}}
>
<option value="">All</option>
<option value="unsorted">Unsorted</option>
{Object.keys(collections).map((name) => {
return <option value={name}>{name}</option>;
})}
</select>
</>
) : null}
</div>
<div className="clip-table" style={{ margin: 'auto' }}>
{videos.map((video, index) => {
let opClass;
let opFn;
switch (op) {
case 'remove':
opClass = 'removeable';
break;
case 'add':
opClass = 'addable';
break;
case 'open':
default:
opClass = 'openable';
break;
}
return (
<div key={`video-${index}`}>
<div className="video-list-element">
<div
className="video-list-element"
onClick={() => {
opFn(collectionId, videoId);
}}
>
<div className={opClass}>
<img
src={`game://${game}/${video._id}.jpg`}
/>
</div>
<div>{video._id.replace(/_/g, ' ')}</div>
</div>
</div>
{includeDelete ? (
<div>
<button
type="button"
onClick={() => {
onDelete(video._id, game);
}}
>
Delete
</button>
</div>
) : null}
</div>
);
})}
</div>
</div>
);
};
100 changes: 52 additions & 48 deletions src/renderer/components/SubtitleList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,54 +110,58 @@ export default ({
</Link>
</div>
<h3>Subtitles</h3>
<table className="subtitle-list">
<thead>
<tr>
<th>Index</th>
<th>In</th>
<th>Out</th>
<th></th>
</tr>
</thead>
<tbody>
{subs.map((sub) => {
return (
<tr
className={
sub.index === currentSub ? 'selected' : null
}
style={{ cursor: 'pointer' }}
onClick={() => {
onSelectSub(sub.index);
}}
>
<td>[{sub.index}]</td>
<td>
{convertMillisecondsToTimestamp(
sub.startTime
)}
</td>
<td>
{convertMillisecondsToTimestamp(
sub.endTime
)}
</td>
<td>
<button
onClick={(e) => {
onSubsChange('remove', sub);
onSelectSub(null);
e.stopPropagation();
}}
>
Remove
</button>
</td>
</tr>
);
})}
</tbody>
</table>
<div className="subtitle-list">
<table>
<thead>
<tr>
<th>Index</th>
<th>In</th>
<th>Out</th>
<th></th>
</tr>
</thead>
<tbody>
{subs.map((sub) => {
return (
<tr
className={
sub.index === currentSub
? 'selected'
: null
}
style={{ cursor: 'pointer' }}
onClick={() => {
onSelectSub(sub.index);
}}
>
<td>[{sub.index}]</td>
<td>
{convertMillisecondsToTimestamp(
sub.startTime
)}
</td>
<td>
{convertMillisecondsToTimestamp(
sub.endTime
)}
</td>
<td>
<button
onClick={(e) => {
onSubsChange('remove', sub);
onSelectSub(null);
e.stopPropagation();
}}
>
Remove
</button>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
<button
onClick={() => {
onSubsChange('add', {
Expand Down
Loading

0 comments on commit 379cdc6

Please sign in to comment.