Files
suwayomi-material-you-webui/webUI/react/src/screens/Manga.tsx

86 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-03-18 22:55:17 +03:30
/* eslint-disable @typescript-eslint/no-unused-vars */
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
2021-01-26 23:32:12 +03:30
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
2021-01-22 17:00:33 +03:30
import React, { useEffect, useState, useContext } from 'react';
2021-03-18 22:55:17 +03:30
import { makeStyles, Theme } from '@material-ui/core/styles';
2021-01-19 20:20:28 +03:30
import { useParams } from 'react-router-dom';
2021-03-18 22:55:17 +03:30
import CircularProgress from '@material-ui/core/CircularProgress';
2021-01-19 20:20:28 +03:30
import ChapterCard from '../components/ChapterCard';
import MangaDetails from '../components/MangaDetails';
2021-03-08 21:04:42 +03:30
import NavbarContext from '../context/NavbarContext';
import client from '../util/client';
2021-01-19 20:20:28 +03:30
2021-03-18 22:55:17 +03:30
const useStyles = makeStyles((theme: Theme) => ({
root: {
[theme.breakpoints.up('md')]: {
display: 'flex',
},
},
2021-03-19 14:52:20 +03:30
chapters: {
listStyle: 'none',
padding: 0,
[theme.breakpoints.up('md')]: {
width: '50%',
marginLeft: '50%',
},
},
2021-03-18 22:55:17 +03:30
loading: {
margin: '10px 0',
display: 'flex',
justifyContent: 'center',
},
}));
2021-01-19 20:20:28 +03:30
export default function Manga() {
2021-03-18 22:55:17 +03:30
const classes = useStyles();
const { setTitle } = useContext(NavbarContext);
useEffect(() => { setTitle('Manga'); }, []); // delegate setting topbar action to MangaDetails
2021-03-09 16:44:09 +03:30
2021-01-19 20:20:28 +03:30
const { id } = useParams<{id: string}>();
2021-01-19 21:02:57 +03:30
const [manga, setManga] = useState<IManga>();
const [chapters, setChapters] = useState<IChapter[]>([]);
useEffect(() => {
client.get(`/api/v1/manga/${id}/`)
.then((response) => response.data)
2021-01-22 17:00:33 +03:30
.then((data: IManga) => {
setManga(data);
setTitle(data.title);
});
2021-01-19 21:02:57 +03:30
}, []);
useEffect(() => {
client.get(`/api/v1/manga/${id}/chapters`)
.then((response) => response.data)
2021-01-19 21:02:57 +03:30
.then((data) => setChapters(data));
}, []);
2021-03-18 22:55:17 +03:30
const chapterCards = (
2021-03-19 14:52:20 +03:30
<ol className={classes.chapters}>
2021-03-18 22:55:17 +03:30
{chapters.length === 0
&& (
<div className={classes.loading}>
<CircularProgress thickness={5} />
</div>
) }
{chapters.map((chapter) => (<ChapterCard chapter={chapter} />))}
2021-01-19 21:02:57 +03:30
</ol>
2021-03-18 22:55:17 +03:30
);
2021-01-19 21:02:57 +03:30
2021-01-19 20:20:28 +03:30
return (
2021-03-18 22:55:17 +03:30
<div className={classes.root}>
{manga && <MangaDetails manga={manga} />}
2021-01-19 21:02:57 +03:30
{chapterCards}
2021-03-18 22:55:17 +03:30
</div>
2021-01-19 20:20:28 +03:30
);
}