Skip to content

Commit

Permalink
Change dropzone to be a global invisible component
Browse files Browse the repository at this point in the history
  • Loading branch information
hockyy committed May 7, 2023
1 parent 3129046 commit 4de5426
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 36 deletions.
4 changes: 2 additions & 2 deletions MiteiruNotes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Video - 0
Drop Zone - 4
Subtitle Container - 3
Subtitle - 10
Video Controller - 15
Meaning box - 18
Side bar - 19
Drop Zone - 20
Side bar - 19
5 changes: 3 additions & 2 deletions renderer/components/DataStructures.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {getFurigana, isMixedJapanese} from "shunou";
import {getFurigana} from "shunou";
import fs from 'fs';
import {parse as parseSRT} from '@plussub/srt-vtt-parser';
import {parse as parseASS} from 'ass-compiler';
import languageEncoding from "detect-file-encoding-and-language";
import iconv from "iconv-lite"
import {Dispatch, SetStateAction} from "react";
import {randomUUID} from "crypto";

const languageMap = {
'japanese': 'JP',
Expand Down Expand Up @@ -48,7 +50,6 @@ export class SubtitleContainer {
if (filename === '') return
const subtitleContainer = new SubtitleContainer('', mecab);
let entries;
console.log(filename)
const buffer = await fs.promises.readFile(filename)
const blob = new Blob([buffer]);

Expand Down
5 changes: 1 addition & 4 deletions renderer/components/KeyboardHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ const shortcutInformation = [{
description: "Toggle Pause"
},
{
key: "X",
description: "Toggle Dropzone"
}, {
key: "Z",
description: "Toggle Video Control Bar"
}, {
key: "C",
key: "X",
description: "Toggle Sidebar"
}, {
key: "Q",
Expand Down
27 changes: 13 additions & 14 deletions renderer/components/MiteiruDropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,23 @@ const ActiveDropzoneCue = ({isActive}) => {

export const MiteiruDropzone = ({onDrop}) => {

const {getRootProps, getInputProps, isDragActive} = useDropzone({
const {getRootProps} = useDropzone({
noClick: true,
onDrop,
noKeyboard: true,
noDragEventsBubbling: true
})

return (<div>
<div {...getRootProps()} style={{
zIndex: 20,
backgroundColor: "rgba(171,248,255,0.45)",
position: "fixed",
top: "0vh",
height: "100vh",
width: "100vw"
}}>
<input {...getInputProps()}/>
<ActiveDropzoneCue isActive={isDragActive}/>
</div>
</div>)
return (
<div {...getRootProps()} className={"unselectable"} style={{
zIndex: 4,
position: "fixed",
top: "0vh",
height: "100vh",
width: "100vw"

}}>
</div>)
}

export default MiteiruDropzone;
4 changes: 2 additions & 2 deletions renderer/components/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useEffect, useState} from "react";

const toastTimeout = 3000
export const TOAST_TIMEOUT = 3000

const toastHidden = ["", "hidden"]
export const Toast = ({info}) => {
Expand All @@ -11,7 +11,7 @@ export const Toast = ({info}) => {
(function () {
setLastToast(info)
})();
}, toastTimeout)
}, TOAST_TIMEOUT)
}
return;
}, [info])
Expand Down
2 changes: 1 addition & 1 deletion renderer/components/VideoController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const VideoController = ({
window.removeEventListener('keydown', handleVideoController);
};
}, []);
return <div className={'z-[15]'}>
return <div>
<div className={"w-[100vw] h-6 content-center -mb-4"}>
<VideoSeekSlider
max={duration}
Expand Down
33 changes: 22 additions & 11 deletions renderer/pages/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import MeaningBox from "../components/MeaningBox";
import {useRouter} from "next/router";
import {ipcRenderer} from "electron";
import {VideoController} from "../components/VideoController";
import Toast from "../components/Toast";
import Toast, {TOAST_TIMEOUT} from "../components/Toast";
import {Sidebar} from "../components/Sidebar";
import {defaultPrimarySubtitleStyling, defaultSecondarySubtitleStyling} from "../utils/CJKStyling";
import {randomUUID} from "crypto";
Expand Down Expand Up @@ -41,14 +41,24 @@ function Video() {
}
if (currentPath.endsWith('.srt') || currentPath.endsWith('.vtt') || currentPath.endsWith('.ass')) {
setToastInfo({
message: 'Loading subtitles, please wait!',
message: 'Loading subtitle, please wait!',
update: randomUUID()
})
});
const toastSetter = setInterval(() => {
console.log("WTF");
setToastInfo({
message: 'Still loading subtitle, please wait!',
update: randomUUID()
})
}, TOAST_TIMEOUT);
const draggedSubtitle = {
type: 'text/plain',
src: `${currentPath}`
}
console.log(toastSetter)
const tmpSub = await SubtitleContainer.create(draggedSubtitle.src, mecab);
clearInterval(toastSetter);
console.log("OK")
if (tmpSub.language === "JP") {
setPrimarySub(tmpSub)
} else {
Expand Down Expand Up @@ -90,11 +100,9 @@ function Video() {
})
// https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/
const handleKeyPress = (event) => {
if (event.code === "KeyX") {
setDragDrop((old) => {
return !old
})
} else if (event.code === "Escape") {
event.preventDefault()
event.stopPropagation()
if (event.code === "Escape") {
setMeaning("")
} else if (event.code === "KeyQ") {
router.push('/home')
Expand All @@ -104,7 +112,7 @@ function Video() {
setShowController((old) => {
return !old
})
} else if (event.code === "KeyC") {
} else if (event.code === "KeyX") {
setShowSidebar((old) => {
return !old
})
Expand All @@ -121,6 +129,7 @@ function Video() {
}, []);
return (
<React.Fragment>

<div>
<Toast info={toastInfo}/>
<MeaningBox meaning={meaning} setMeaning={setMeaning} mecab={mecab}/>
Expand All @@ -136,7 +145,7 @@ function Video() {
durationDisplay: true
}
}} onReady={readyCallback} setCurrentTime={setCurrentTime}/>
<div className={"flex flex-col justify-end bottom-0 z-[3] fixed h-[100vh] w-[100vw]"}>
<div>
<PrimarySubtitle setMeaning={setMeaning}
currentTime={currentTime}
subtitle={primarySub}
Expand All @@ -147,6 +156,8 @@ function Video() {
subtitle={secondarySub}
shift={secondaryShift}
subtitleStyling={secondaryStyling}/>
</div>
<div className={"flex flex-col justify-end bottom-0 z-[15] fixed"}>
{player && <VideoController player={player}
currentTime={currentTime}
setCurrentTime={setCurrentTime}
Expand All @@ -157,10 +168,10 @@ function Video() {
setInfo={setToastInfo}
setShowSidebar={setShowSidebar}/>}
</div>
{mecab !== '' && <MiteiruDropzone onDrop={onLoadFiles}/>}


</div>
{mecab !== '' && dragDrop && <MiteiruDropzone onDrop={onLoadFiles}/>}
<Sidebar showSidebar={showSidebar} setShowSidebar={setShowSidebar}
primaryStyling={primaryStyling}
setPrimaryStyling={setPrimaryStyling}
Expand Down

0 comments on commit 4de5426

Please sign in to comment.