2021-01-22 17:00:33 +03:30
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2021-01-19 14:47:07 +03:30
|
|
|
import { useParams } from 'react-router-dom';
|
2021-01-20 15:26:52 +03:30
|
|
|
import MangaGrid from '../components/MangaGrid';
|
2021-01-22 17:00:33 +03:30
|
|
|
import NavBarTitle from '../context/NavbarTitle';
|
2021-01-19 14:47:07 +03:30
|
|
|
|
|
|
|
export default function MangaList(props: { popular: boolean }) {
|
|
|
|
const { sourceId } = useParams<{sourceId: string}>();
|
2021-01-22 17:00:33 +03:30
|
|
|
const { setTitle } = useContext(NavBarTitle);
|
2021-01-19 14:47:07 +03:30
|
|
|
const [mangas, setMangas] = useState<IManga[]>([]);
|
2021-01-19 15:07:20 +03:30
|
|
|
const [lastPageNum] = useState<number>(1);
|
2021-01-19 14:47:07 +03:30
|
|
|
|
2021-01-22 17:00:33 +03:30
|
|
|
useEffect(() => {
|
|
|
|
fetch(`http://127.0.0.1:4567/api/v1/source/${sourceId}`)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data: { name: string }) => setTitle(data.name));
|
|
|
|
}, []);
|
|
|
|
|
2021-01-19 14:47:07 +03:30
|
|
|
useEffect(() => {
|
|
|
|
const sourceType = props.popular ? 'popular' : 'latest';
|
2021-01-19 15:07:20 +03:30
|
|
|
fetch(`http://127.0.0.1:4567/api/v1/source/${sourceId}/${sourceType}/${lastPageNum}`)
|
2021-01-19 14:47:07 +03:30
|
|
|
.then((response) => response.json())
|
2021-01-19 20:20:28 +03:30
|
|
|
.then((data: { title: string, thumbnail_url: string, id:number }[]) => setMangas(
|
|
|
|
data.map((it) => ({ title: it.title, thumbnailUrl: it.thumbnail_url, id: it.id })),
|
2021-01-19 14:47:07 +03:30
|
|
|
));
|
|
|
|
}, []);
|
|
|
|
|
2021-01-20 15:26:52 +03:30
|
|
|
return <MangaGrid mangas={mangas} />;
|
2021-01-19 14:47:07 +03:30
|
|
|
}
|