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

47 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-01-26 23:32:12 +03:30
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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-01-19 20:20:28 +03:30
import { useParams } from 'react-router-dom';
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
export default function Manga() {
const { id } = useParams<{id: string}>();
2021-03-08 21:04:42 +03:30
const { setTitle } = useContext(NavbarContext);
2021-01-19 20:20:28 +03:30
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));
}, []);
const chapterCards = chapters.map((chapter) => (
<ol style={{ listStyle: 'none', padding: 0 }}>
<ChapterCard chapter={chapter} />
</ol>
));
2021-01-19 20:20:28 +03:30
return (
<>
2021-02-13 21:12:18 +03:30
{manga && <MangaDetails manga={manga} />}
2021-01-19 21:02:57 +03:30
{chapterCards}
2021-01-19 20:20:28 +03:30
</>
);
}