2021-01-08 17:26:38 +09:00
|
|
|
import React, { useState, useEffect, useContext } from 'react';
|
2021-01-08 10:46:19 +09:00
|
|
|
import { Redirect, Route, Switch, useHistory, useRouteMatch, match as MatchType, Link as RouterLink, useParams, useLocation } from 'react-router-dom';
|
2021-01-11 23:37:29 +09:00
|
|
|
import DocumentAccessor, { Document } from '../accessor/document';
|
2021-01-06 20:16:27 +09:00
|
|
|
import { LoadingCircle } from '../component/loading';
|
|
|
|
import { Link, Paper, makeStyles, Theme, Box, useTheme, Typography } from '@material-ui/core';
|
2021-01-08 10:46:19 +09:00
|
|
|
import {ArrowBack as ArrowBackIcon } from '@material-ui/icons';
|
2021-01-09 02:28:40 +09:00
|
|
|
import { getPresenter } from './reader/reader';
|
2021-01-11 20:47:42 +09:00
|
|
|
import { BackItem, CommonMenuList, ContentInfo, Headline, NavItem, NavList } from '../component/mod';
|
2021-01-06 20:16:27 +09:00
|
|
|
|
|
|
|
export const makeContentInfoUrl = (id: number) => `/doc/${id}`;
|
|
|
|
export const makeMangaReaderUrl = (id: number) => `/doc/${id}/reader`;
|
|
|
|
|
2021-01-11 23:37:29 +09:00
|
|
|
type DocumentState = {
|
|
|
|
doc: Document | undefined,
|
2021-01-06 20:16:27 +09:00
|
|
|
notfound: boolean,
|
|
|
|
}
|
|
|
|
|
2021-01-09 02:28:40 +09:00
|
|
|
const useStyles = makeStyles((theme:Theme)=>({
|
|
|
|
noPaddingContent:{
|
|
|
|
display:'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
flexGrow: 1,
|
|
|
|
},
|
|
|
|
noPaddingToolbar:{
|
|
|
|
flex: '0 1 auto',
|
|
|
|
...theme.mixins.toolbar,
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2021-01-11 23:37:29 +09:00
|
|
|
export const DocumentAbout = (prop: { match: MatchType }) => {
|
2021-01-08 10:46:19 +09:00
|
|
|
const match = useRouteMatch<{id:string}>("/doc/:id");
|
2021-01-06 20:16:27 +09:00
|
|
|
if (match == null) {
|
|
|
|
throw new Error("unreachable");
|
|
|
|
}
|
2021-01-08 10:46:19 +09:00
|
|
|
const id = Number.parseInt(match.params['id']);
|
2021-01-11 23:37:29 +09:00
|
|
|
const [info, setInfo] = useState<DocumentState>({ doc: undefined, notfound:false });
|
|
|
|
const menu_list = (link?:string) => <CommonMenuList url={link}></CommonMenuList>;
|
2021-01-09 02:28:40 +09:00
|
|
|
|
2021-01-06 20:16:27 +09:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
if (!isNaN(id)) {
|
2021-01-11 23:37:29 +09:00
|
|
|
const c = await DocumentAccessor.findById(id);
|
|
|
|
setInfo({ doc: c, notfound: c === undefined });
|
2021-01-06 20:16:27 +09:00
|
|
|
}
|
2021-01-11 23:37:29 +09:00
|
|
|
})();
|
2021-01-06 20:16:27 +09:00
|
|
|
}, []);
|
2021-01-09 02:28:40 +09:00
|
|
|
const classes = useStyles();
|
2021-01-11 23:37:29 +09:00
|
|
|
console.log(info.doc);
|
2021-01-06 20:16:27 +09:00
|
|
|
if (isNaN(id)) {
|
2021-01-08 10:46:19 +09:00
|
|
|
return (
|
2021-01-08 17:26:38 +09:00
|
|
|
<Headline menu={menu_list()}>
|
2021-01-08 10:46:19 +09:00
|
|
|
<Typography variant='h2'>Oops. Invalid ID</Typography>
|
|
|
|
</Headline>
|
|
|
|
);
|
2021-01-06 20:16:27 +09:00
|
|
|
}
|
|
|
|
else if(info.notfound){
|
2021-01-08 10:46:19 +09:00
|
|
|
return (
|
2021-01-08 17:26:38 +09:00
|
|
|
<Headline menu={menu_list()}>
|
2021-01-08 10:46:19 +09:00
|
|
|
<Typography variant='h2'>Content has been removed.</Typography>
|
|
|
|
</Headline>
|
|
|
|
)
|
2021-01-06 20:16:27 +09:00
|
|
|
}
|
2021-01-11 23:37:29 +09:00
|
|
|
else if (info.doc === undefined) {
|
2021-01-08 17:26:38 +09:00
|
|
|
return (<Headline menu={menu_list()}>
|
2021-01-08 10:46:19 +09:00
|
|
|
<LoadingCircle />
|
|
|
|
</Headline>
|
|
|
|
);
|
2021-01-06 20:16:27 +09:00
|
|
|
}
|
2021-01-08 17:26:38 +09:00
|
|
|
else{
|
2021-01-11 23:37:29 +09:00
|
|
|
const ReaderPage = getPresenter(info.doc);
|
2021-01-08 17:26:38 +09:00
|
|
|
return (<Switch>
|
2021-01-06 20:16:27 +09:00
|
|
|
<Route exact path={`${prop.match.path}/:id`}>
|
2021-01-08 17:26:38 +09:00
|
|
|
<Headline menu={menu_list()}>
|
2021-01-11 23:37:29 +09:00
|
|
|
<ContentInfo document={info.doc}></ContentInfo>
|
2021-01-08 10:46:19 +09:00
|
|
|
</Headline>
|
2021-01-06 20:16:27 +09:00
|
|
|
</Route>
|
|
|
|
<Route exact path={`${prop.match.path}/:id/reader`}>
|
2021-01-09 02:28:40 +09:00
|
|
|
<Headline menu={menu_list(`${prop.match.path}/${id}`)} classes={{
|
|
|
|
content:classes.noPaddingContent,
|
|
|
|
toolbar:classes.noPaddingToolbar
|
|
|
|
}}>
|
2021-01-11 23:37:29 +09:00
|
|
|
<ReaderPage doc={info.doc}></ReaderPage>
|
2021-01-08 10:46:19 +09:00
|
|
|
</Headline>
|
2021-01-06 20:16:27 +09:00
|
|
|
</Route>
|
|
|
|
<Route>
|
2021-01-08 17:26:38 +09:00
|
|
|
<Headline menu={menu_list()}>
|
2021-01-08 10:46:19 +09:00
|
|
|
<div>404 Not Found invalid url : {prop.match.path}</div>
|
|
|
|
</Headline>
|
2021-01-06 20:16:27 +09:00
|
|
|
</Route>
|
|
|
|
</Switch>);
|
2021-01-08 17:26:38 +09:00
|
|
|
}
|
2021-01-06 20:16:27 +09:00
|
|
|
}
|