21 lines
872 B
TypeScript
Raw Normal View History

2021-01-19 14:47:07 +03:30
import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
2021-01-20 15:26:52 +03:30
import MangaGrid from '../components/MangaGrid';
2021-01-19 14:47:07 +03:30
export default function MangaList(props: { popular: boolean }) {
const { sourceId } = useParams<{sourceId: string}>();
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
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
}