2021-05-15 17:18:57 +04:30
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
2021-05-17 01:38:59 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* 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-05-15 17:18:57 +04:30
|
|
|
import { makeStyles } from '@material-ui/core/styles';
|
2021-05-18 02:26:45 +04:30
|
|
|
import React, { useEffect, useRef, useState } from 'react';
|
2021-05-17 09:57:14 +02:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2021-05-17 01:38:59 +04:30
|
|
|
import Page from '../Page';
|
2021-05-15 17:18:57 +04:30
|
|
|
|
|
|
|
|
const useStyles = makeStyles({
|
|
|
|
|
reader: {
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
margin: '0 auto',
|
|
|
|
|
width: '100%',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-17 09:57:14 +02:00
|
|
|
export default function VerticalReader(props: IReaderProps) {
|
|
|
|
|
const {
|
2021-05-18 01:10:28 +04:30
|
|
|
pages, settings, setCurPage, curPage, manga, chapter, nextChapter,
|
2021-05-17 09:57:14 +02:00
|
|
|
} = props;
|
2021-05-15 17:18:57 +04:30
|
|
|
|
|
|
|
|
const classes = useStyles();
|
2021-05-17 09:57:14 +02:00
|
|
|
const history = useHistory();
|
|
|
|
|
|
2021-05-18 02:26:45 +04:30
|
|
|
const [initialScroll, setInitialScroll] = useState(-1);
|
|
|
|
|
const initialPageRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
2021-05-17 09:57:14 +02:00
|
|
|
const handleLoadNextonEnding = () => {
|
|
|
|
|
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
|
2021-05-18 01:10:28 +04:30
|
|
|
nextChapter();
|
2021-05-17 09:57:14 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (settings.loadNextonEnding) { window.addEventListener('scroll', handleLoadNextonEnding); }
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener('scroll', handleLoadNextonEnding);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2021-05-15 17:18:57 +04:30
|
|
|
|
2021-05-18 02:26:45 +04:30
|
|
|
useEffect(() => {
|
|
|
|
|
if ((chapter as IChapter).lastPageRead > -1) {
|
|
|
|
|
setInitialScroll((chapter as IChapter).lastPageRead);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (initialScroll > -1) {
|
|
|
|
|
initialPageRef.current?.scrollIntoView();
|
|
|
|
|
}
|
|
|
|
|
}, [initialScroll, initialPageRef.current]);
|
|
|
|
|
|
2021-05-15 17:18:57 +04:30
|
|
|
return (
|
|
|
|
|
<div className={classes.reader}>
|
|
|
|
|
{
|
|
|
|
|
pages.map((page) => (
|
|
|
|
|
<Page
|
|
|
|
|
key={page.index}
|
|
|
|
|
index={page.index}
|
|
|
|
|
src={page.src}
|
|
|
|
|
setCurPage={setCurPage}
|
|
|
|
|
settings={settings}
|
2021-05-18 02:26:45 +04:30
|
|
|
ref={page.index === initialScroll ? initialPageRef : null}
|
2021-05-15 17:18:57 +04:30
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|