staisfying results? with chapters scrolling

This commit is contained in:
Aria Moradi
2021-05-13 17:46:40 +04:30
parent 1e2eb11c13
commit dc012edf7d
8 changed files with 140 additions and 60 deletions
+46 -14
View File
@@ -7,9 +7,9 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import React, { useEffect, useState, useContext } from 'react';
import { makeStyles, Theme } from '@material-ui/core/styles';
import { makeStyles, Theme, useTheme } from '@material-ui/core/styles';
import { useParams } from 'react-router-dom';
import CircularProgress from '@material-ui/core/CircularProgress';
import { Virtuoso } from 'react-virtuoso';
import ChapterCard from '../components/ChapterCard';
import MangaDetails from '../components/MangaDetails';
import NavbarContext from '../context/NavbarContext';
@@ -41,13 +41,26 @@ const useStyles = makeStyles((theme: Theme) => ({
},
}));
const InnerItem = React.memo(({ chapters, index }: any) => {
React.useEffect(() => {
console.log('inner mounting', index);
return () => {
console.log('inner unmounting', index);
};
}, [index]);
return (
<ChapterCard chapter={chapters[index]} />
);
});
export default function Manga() {
const classes = useStyles();
const theme = useTheme();
const { setTitle } = useContext(NavbarContext);
useEffect(() => { setTitle('Manga'); }, []); // delegate setting topbar action to MangaDetails
const { id } = useParams<{id: string}>();
const { id } = useParams<{ id: string }>();
const [manga, setManga] = useState<IManga>();
const [chapters, setChapters] = useState<IChapter[]>([]);
@@ -67,16 +80,10 @@ export default function Manga() {
.then((data) => setChapters(data));
}, []);
const chapterCards = (
<LoadingPlaceholder
shouldRender={chapters.length > 0}
>
<ol className={classes.chapters}>
{chapters.map((chapter) => (<ChapterCard chapter={chapter} />))}
</ol>
</LoadingPlaceholder>
);
const itemContent = (index:any) => {
console.log('providing content', index);
return <InnerItem chapters={chapters} index={index} />;
};
return (
<div className={classes.root}>
@@ -85,7 +92,32 @@ export default function Manga() {
component={MangaDetails}
componentProps={{ manga }}
/>
{chapterCards}
<LoadingPlaceholder
shouldRender={chapters.length > 0}
>
{/* <ol >
{chapters.map((chapter) => ())}
</ol> */}
<Virtuoso
style={
{
width: '100vw',
height: '100%',
[theme.breakpoints.up('md')]: {
height: 'calc(100vh - 64px)',
width: '50vw',
},
}
}
className={classes.chapters}
totalCount={chapters.length}
itemContent={itemContent}
useWindowScroll={window.innerWidth < 960}
overscan={window.innerHeight * 0.5}
/>
</LoadingPlaceholder>
</div>
);
}
+1 -1
View File
@@ -50,7 +50,7 @@ export default function Reader() {
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
const { chapterIndex, mangaId } = useParams<{chapterIndex: string, mangaId: string}>();
const { chapterIndex, mangaId } = useParams<{ chapterIndex: string, mangaId: string }>();
const [manga, setManga] = useState<IMangaCard | IManga>({ id: +mangaId, title: '', thumbnailUrl: '' });
const [chapter, setChapter] = useState<IChapter | IPartialChpter>(initialChapter());
const [curPage, setCurPage] = useState<number>(0);
+1 -1
View File
@@ -27,7 +27,7 @@ export default function SearchSingle() {
const { setTitle, setAction } = useContext(NavbarContext);
useEffect(() => { setTitle('Search'); setAction(<></>); }, []);
const { sourceId } = useParams<{sourceId: string}>();
const { sourceId } = useParams<{ sourceId: string }>();
const classes = useStyles();
const [error, setError] = useState<boolean>(false);
const [mangas, setMangas] = useState<IMangaCard[]>([]);
+1 -1
View File
@@ -15,7 +15,7 @@ export default function SourceMangas(props: { popular: boolean }) {
const { setTitle, setAction } = useContext(NavbarContext);
useEffect(() => { setTitle('Source'); setAction(<></>); }, []);
const { sourceId } = useParams<{sourceId: string}>();
const { sourceId } = useParams<{ sourceId: string }>();
const [mangas, setMangas] = useState<IMangaCard[]>([]);
const [hasNextPage, setHasNextPage] = useState<boolean>(false);
const [lastPageNum, setLastPageNum] = useState<number>(1);