This commit is contained in:
User
2024-12-28 22:41:16 -05:00
parent 55414d56a4
commit 2b52f7f15a
8 changed files with 163 additions and 40 deletions

View File

@@ -18,7 +18,7 @@ export default function Read({ auth, comic, chapter }) {
const validReadingModes = ['rtl', 'utd'];
const [readingMode, setReadingMode] = useState('rtl'); // rtl, utd
const [isTwoPagesPerScreen, setIsTwoPagePerScreen] = useState(false);
const [isTwoPagesPerScreen, setIsTwoPagePerScreen] = useState(false); // TODO
const [currentImage, setCurrentImage] = useState(1);
const windowSize = useWindowSize();
@@ -228,13 +228,13 @@ export default function Read({ auth, comic, chapter }) {
let visibleImageIndex = 0;
// Determine which image is visible based on scroll position
images.forEach((image, index) => {
images.forEach((image, i) => {
const imageTop = image.offsetTop; // Distance from top of the container
const imageBottom = imageTop + image.offsetHeight;
// Check if the image is in the visible area
if (containerScrollTop + 80 >= imageTop && containerScrollTop < imageBottom) {
visibleImageIndex = index;
visibleImageIndex = i;
}
});
@@ -242,12 +242,9 @@ export default function Read({ auth, comic, chapter }) {
setCurrentImage(visibleImageIndex + 1);
};
const throttledHandleScroll = throttle(handleScroll, 100); // Throttle for performance
const throttledHandleScroll = throttle(handleScroll, 1000); // Throttle for performance
ref.current.addEventListener("scroll", throttledHandleScroll);
// Initial check for visible image
handleScroll();
return () => {
if (ref.current) {
ref.current.removeEventListener("scroll", throttledHandleScroll);