ionian/src/client/page/reader/manga.tsx

48 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-01-06 20:16:27 +09:00
import React, {useState, useEffect} from 'react';
2021-01-09 02:28:40 +09:00
import { Typography, useTheme } from '@material-ui/core';
2021-01-11 23:37:29 +09:00
import { Document } from '../../accessor/document';
2021-01-06 20:16:27 +09:00
type MangaType = "manga"|"artist cg"|"donjinshi"|"western"
export type PresentableTag = {
artist:string[],
group: string[],
series: string[],
type: MangaType,
character: string[],
tags: string[],
}
2021-01-11 23:37:29 +09:00
export const MangaReader = (props:{doc:Document})=>{
2021-01-09 02:28:40 +09:00
const theme = useTheme();
2021-01-11 23:37:29 +09:00
const additional = props.doc.additional;
2021-01-09 02:28:40 +09:00
const [curPage,setCurPage] = useState(0);
2021-01-06 20:16:27 +09:00
if(!('page' in additional)){
console.error("invalid content : page read fail : "+ JSON.stringify(additional));
return <Typography>Error. DB error. page restriction</Typography>
}
2021-01-09 02:28:40 +09:00
const PageDown = ()=>setCurPage(Math.max(curPage - 1 , 0));
const PageUP = ()=>setCurPage(Math.min(curPage + 1, page - 1));
2021-01-06 20:16:27 +09:00
const page:number = additional['page'] as number;
2021-01-09 02:28:40 +09:00
const onKeyUp = (e: KeyboardEvent)=>{
if(e.code === "ArrowLeft"){
PageDown();
}
else if(e.code === "ArrowRight"){
PageUP();
}
}
useEffect(()=>{
document.addEventListener("keydown",onKeyUp);
return ()=>{
document.removeEventListener("keydown",onKeyUp);
}
});
//theme.mixins.toolbar.minHeight;
return (<div style={{overflow: 'hidden', alignSelf:'center'}}>
2021-01-11 23:37:29 +09:00
<img onClick={PageUP} src={`/api/doc/${props.doc.id}/manga/${curPage}`}
2021-01-09 02:28:40 +09:00
style={{maxWidth:'100%', maxHeight:'calc(100vh - 64px)'}}></img>
</div>);
2021-01-06 20:16:27 +09:00
}
export default MangaReader;