2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* 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-12-13 19:52:56 +05:30
|
|
|
import { Box } from '@mui/system';
|
2021-10-30 16:10:34 +03:30
|
|
|
import MangaDetails from 'components/MangaDetails';
|
|
|
|
|
import NavbarContext from 'components/context/NavbarContext';
|
2021-05-27 05:13:01 +04:30
|
|
|
import client from 'util/client';
|
2021-10-30 16:10:34 +03:30
|
|
|
import LoadingPlaceholder from 'components/util/LoadingPlaceholder';
|
2021-12-19 18:02:02 +03:30
|
|
|
import ChapterList from 'components/chapter/ChapterList';
|
2021-12-13 19:52:56 +05:30
|
|
|
import { useParams } from 'react-router-dom';
|
2021-05-30 04:01:49 +04:30
|
|
|
|
2021-01-19 20:20:28 +03:30
|
|
|
export default function Manga() {
|
2021-03-17 19:17:03 +03:30
|
|
|
const { setTitle } = useContext(NavbarContext);
|
|
|
|
|
useEffect(() => { setTitle('Manga'); }, []); // delegate setting topbar action to MangaDetails
|
2021-03-09 16:44:09 +03:30
|
|
|
|
2021-05-13 17:46:40 +04:30
|
|
|
const { id } = useParams<{ id: string }>();
|
2021-01-19 20:20:28 +03:30
|
|
|
|
2021-01-19 21:02:57 +03:30
|
|
|
const [manga, setManga] = useState<IManga>();
|
2021-05-30 04:01:49 +04:30
|
|
|
|
2021-01-19 21:02:57 +03:30
|
|
|
useEffect(() => {
|
2021-05-15 13:43:26 +04:30
|
|
|
if (manga === undefined || !manga.freshData) {
|
|
|
|
|
client.get(`/api/v1/manga/${id}/?onlineFetch=${manga !== undefined}`)
|
|
|
|
|
.then((response) => response.data)
|
|
|
|
|
.then((data: IManga) => {
|
|
|
|
|
setManga(data);
|
|
|
|
|
setTitle(data.title);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, [manga]);
|
2021-01-19 21:02:57 +03:30
|
|
|
|
2021-01-19 20:20:28 +03:30
|
|
|
return (
|
2021-11-17 16:58:39 +03:30
|
|
|
<Box sx={{ display: { md: 'flex' }, overflow: 'hidden' }}>
|
2021-03-27 22:21:39 +04:30
|
|
|
<LoadingPlaceholder
|
|
|
|
|
shouldRender={manga !== undefined}
|
|
|
|
|
component={MangaDetails}
|
|
|
|
|
componentProps={{ manga }}
|
|
|
|
|
/>
|
2021-05-13 17:46:40 +04:30
|
|
|
|
2021-12-13 19:52:56 +05:30
|
|
|
<ChapterList id={id} />
|
2021-11-17 16:58:39 +03:30
|
|
|
</Box>
|
2021-01-19 20:20:28 +03:30
|
|
|
);
|
|
|
|
|
}
|