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

49 lines
1.9 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, { 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-03-08 21:04:42 +03:30
import NavbarContext from '../context/NavbarContext';
import client from '../util/client';
2021-01-19 14:47:07 +03:30
2021-02-20 01:23:52 +03:30
export default function SourceMangas(props: { popular: boolean }) {
2021-03-09 16:44:09 +03:30
const { setTitle, setAction } = useContext(NavbarContext);
useEffect(() => { setTitle('Source'); setAction(<></>); }, []);
2021-01-19 14:47:07 +03:30
const { sourceId } = useParams<{sourceId: string}>();
const [mangas, setMangas] = useState<IMangaCard[]>([]);
2021-01-22 21:11:00 +03:30
const [hasNextPage, setHasNextPage] = useState<boolean>(false);
const [lastPageNum, setLastPageNum] = useState<number>(1);
2021-01-19 14:47:07 +03:30
2021-01-22 17:00:33 +03:30
useEffect(() => {
client.get(`/api/v1/source/${sourceId}`)
.then((response) => response.data)
2021-01-22 17:00:33 +03:30
.then((data: { name: string }) => setTitle(data.name));
}, []);
2021-01-19 14:47:07 +03:30
useEffect(() => {
const sourceType = props.popular ? 'popular' : 'latest';
client.get(`/api/v1/source/${sourceId}/${sourceType}/${lastPageNum}`)
.then((response) => response.data)
2021-01-22 21:11:00 +03:30
.then((data: { mangaList: IManga[], hasNextPage: boolean }) => {
setMangas([
...mangas,
...data.mangaList.map((it) => ({
title: it.title, thumbnailUrl: it.thumbnailUrl, id: it.id,
}))]);
setHasNextPage(data.hasNextPage);
});
}, [lastPageNum]);
2021-01-19 14:47:07 +03:30
2021-01-22 21:11:00 +03:30
return (
<MangaGrid
mangas={mangas}
hasNextPage={hasNextPage}
lastPageNum={lastPageNum}
setLastPageNum={setLastPageNum}
/>
);
2021-01-19 14:47:07 +03:30
}