import React, { useState, useEffect } from 'react'; import { Redirect, Route, Switch, useHistory, useRouteMatch, match as MatchType, Link as RouterLink } from 'react-router-dom'; import ContentAccessor, { Content } from '../accessor/contents'; import { LoadingCircle } from '../component/loading'; import { Link, Paper, makeStyles, Theme, Box, useTheme, Typography } from '@material-ui/core'; import { ThumbnailContainer } from '../presenter/presenter'; import { TagChip } from '../component/tagchip'; import { MangaReader } from '../presenter/manga'; export const makeContentInfoUrl = (id: number) => `/doc/${id}`; export const makeMangaReaderUrl = (id: number) => `/doc/${id}/reader`; type ContentInfoState = { content: Content | undefined, notfound: boolean, } export const ContentAbout = (prop: { match: MatchType }) => { const match = useRouteMatch("/doc/:id"); if (match == null) { throw new Error("unreachable"); } const m = /\/doc\/(\d+)/.exec(match.url); const id = m !== null ? Number.parseInt(m[1]) : NaN; const [info, setInfo] = useState({ content: undefined, notfound:false }); useEffect(() => { (async () => { if (!isNaN(id)) { const c = await ContentAccessor.findById(id); setInfo({ content: c, notfound: c === undefined }); } })() }, []); if (isNaN(id)) { return (Oops. Invalid ID) } else if(info.notfound){ return (Content has been removed.) } else if (info.content === undefined) { return (); } else return (
404 Not Found invalid url : {prop.match.path}
); } const useStyles = makeStyles((theme: Theme) => ({ root: { display: "flex", [theme.breakpoints.down("sm")]: { flexDirection: "column", alignItems: "center", } }, thumbnail_content: { maxWidth: '300px', maxHeight: '300px' }, tag_list: { display: 'flex', justifyContent: 'flex-start', flexWrap: 'wrap', overflowY: 'hidden', '& > *': { margin: theme.spacing(0.5), }, }, title: { marginLeft: theme.spacing(1), }, InfoContainer: { display: 'grid', gridTemplateColumns: '100px auto', overflowY: 'hidden', } })) export const ContentInfo = (props: { content: Content, children?: React.ReactNode }) => { const classes = useStyles(); const theme = useTheme(); const content = props?.content; let allTag = content.tags; const artists = allTag.filter(x => x.startsWith("artist:")).map(x => x.substr(7)); allTag = allTag.filter(x => !x.startsWith("artist:")); return ( {content.title} Artist {artists.join(", ")} Tags {allTag.map(x => { return (); })} ); }