/* 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/. */ import React, { useEffect, useState, useContext } from 'react'; import { useParams } from 'react-router-dom'; import ChapterCard from '../components/ChapterCard'; import MangaDetails from '../components/MangaDetails'; import NavbarContext from '../context/NavbarContext'; import client from '../util/client'; export default function Manga() { const { setTitle, setAction } = useContext(NavbarContext); useEffect(() => { setTitle('Manga'); setAction(<>); }, []); const { id } = useParams<{id: string}>(); const [manga, setManga] = useState(); const [source, setSource] = useState(); const [chapters, setChapters] = useState([]); useEffect(() => { client.get(`/api/v1/manga/${id}/`) .then((response) => response.data) .then((data: IManga) => { setManga(data); setTitle(data.title); }); }, []); useEffect(() => { if (manga !== undefined) { client.get(`/api/v1/source/${manga.sourceId}`) .then((response) => response.data) .then((data: ISource) => { setSource(data); }); } }, [manga]); useEffect(() => { client.get(`/api/v1/manga/${id}/chapters`) .then((response) => response.data) .then((data) => setChapters(data)); }, []); const chapterCards = chapters.map((chapter) => (
)); return ( <> {(manga && source) && } {chapterCards} ); }