2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-01-26 23:32:12 +03:30
|
|
|
* 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-09-09 22:57:19 +04:30
|
|
|
import { useParams, useHistory } from 'react-router-dom';
|
|
|
|
|
import IconButton from '@mui/material/IconButton';
|
2021-10-30 16:10:34 +03:30
|
|
|
import MangaGrid from 'components/MangaGrid';
|
|
|
|
|
import NavbarContext from 'components/context/NavbarContext';
|
2021-05-27 05:13:01 +04:30
|
|
|
import client from 'util/client';
|
2021-09-09 22:57:19 +04:30
|
|
|
import SettingsIcon from '@mui/icons-material/Settings';
|
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);
|
2021-09-09 22:57:19 +04:30
|
|
|
const history = useHistory();
|
2021-03-09 16:44:09 +03:30
|
|
|
|
2021-05-13 17:46:40 +04:30
|
|
|
const { sourceId } = useParams<{ sourceId: string }>();
|
2021-09-09 22:57:19 +04:30
|
|
|
const [isConfigurable, setIsConfigurable] = useState<boolean>(false);
|
2021-03-17 19:17:03 +03:30
|
|
|
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-09-18 00:05:00 +04:30
|
|
|
const [fetched, setFetched] = useState<boolean>(false);
|
2021-01-19 14:47:07 +03:30
|
|
|
|
2021-09-09 22:57:19 +04:30
|
|
|
useEffect(() => {
|
2021-09-18 00:05:00 +04:30
|
|
|
setTitle('Source'); // title is later set after a fetch but we set it here once
|
2021-09-13 19:18:21 +04:30
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-09-09 22:57:19 +04:30
|
|
|
setAction(
|
|
|
|
|
<>
|
|
|
|
|
{isConfigurable && (
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => history.push(`/sources/${sourceId}/configure/`)}
|
|
|
|
|
aria-label="display more actions"
|
|
|
|
|
edge="end"
|
|
|
|
|
color="inherit"
|
|
|
|
|
size="large"
|
|
|
|
|
>
|
|
|
|
|
<SettingsIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
)}
|
|
|
|
|
</>,
|
|
|
|
|
);
|
|
|
|
|
}, [isConfigurable]);
|
|
|
|
|
|
2021-01-22 17:00:33 +03:30
|
|
|
useEffect(() => {
|
2021-03-07 22:25:29 +03:30
|
|
|
client.get(`/api/v1/source/${sourceId}`)
|
|
|
|
|
.then((response) => response.data)
|
2021-09-09 22:57:19 +04:30
|
|
|
.then((data: ISource) => {
|
2021-09-18 00:05:00 +04:30
|
|
|
setTitle(data.displayName);
|
2021-09-09 22:57:19 +04:30
|
|
|
setIsConfigurable(data.isConfigurable);
|
|
|
|
|
});
|
2021-01-22 17:00:33 +03:30
|
|
|
}, []);
|
|
|
|
|
|
2021-01-19 14:47:07 +03:30
|
|
|
useEffect(() => {
|
|
|
|
|
const sourceType = props.popular ? 'popular' : 'latest';
|
2021-03-07 22:25:29 +03:30
|
|
|
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);
|
2021-09-18 00:05:00 +04:30
|
|
|
setFetched(true);
|
2021-01-22 21:11:00 +03:30
|
|
|
});
|
|
|
|
|
}, [lastPageNum]);
|
2021-01-19 14:47:07 +03:30
|
|
|
|
2021-09-18 00:05:00 +04:30
|
|
|
let message;
|
2021-09-19 17:30:34 +04:30
|
|
|
let messageExtra;
|
|
|
|
|
|
|
|
|
|
if (fetched) {
|
|
|
|
|
message = 'No manga was found!';
|
|
|
|
|
if (sourceId === '0') {
|
|
|
|
|
messageExtra = (
|
|
|
|
|
<>
|
|
|
|
|
<span>Check out </span>
|
|
|
|
|
<a href="https://github.com/Suwayomi/Tachidesk-Server/wiki/Local-Source">Local source guide</a>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-18 00:05:00 +04:30
|
|
|
|
2021-01-22 21:11:00 +03:30
|
|
|
return (
|
|
|
|
|
<MangaGrid
|
|
|
|
|
mangas={mangas}
|
|
|
|
|
hasNextPage={hasNextPage}
|
|
|
|
|
lastPageNum={lastPageNum}
|
|
|
|
|
setLastPageNum={setLastPageNum}
|
2021-09-18 00:05:00 +04:30
|
|
|
message={message}
|
2021-09-19 17:30:34 +04:30
|
|
|
messageExtra={messageExtra}
|
2021-10-24 22:56:10 +03:30
|
|
|
isLoading={!fetched}
|
2021-01-22 21:11:00 +03:30
|
|
|
/>
|
|
|
|
|
);
|
2021-01-19 14:47:07 +03:30
|
|
|
}
|