From 341fc19d4b7e9d8fb8b9a9d72377cf36565f2f2e Mon Sep 17 00:00:00 2001
From: Wolfgang Müller
Date: Thu, 13 Feb 2025 18:22:51 +0100
Subject: frontend: Increase lookaround when preloading page images

Instead of preloading one image in next and previous direction, preload
two.
---
 frontend/src/lib/reader/PageView.svelte | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

(limited to 'frontend/src/lib/reader/PageView.svelte')

diff --git a/frontend/src/lib/reader/PageView.svelte b/frontend/src/lib/reader/PageView.svelte
index 81fbb97..fc45cfa 100644
--- a/frontend/src/lib/reader/PageView.svelte
+++ b/frontend/src/lib/reader/PageView.svelte
@@ -23,19 +23,24 @@
 	}
 
 	function pagesAround(around: number) {
-		const peek = (at: number) => {
-			if (at < 0 || at >= chunks.length) return [];
+		const pages: PageFragment[] = [];
 
-			const pages: PageFragment[] = [chunks[at].main];
+		const push = (at: number) => {
+			if (at < 0 || at >= chunks.length) return;
+
+			pages.push(chunks[at].main);
 
 			if (chunks[at].secondary) {
 				pages.push(chunks[at].secondary);
 			}
-
-			return pages;
 		};
 
-		return [...peek(lookup[around] + 1), ...peek(lookup[around] - 1)];
+		for (let i = 1; i <= 2; i++) {
+			push(lookup[around] + i);
+			push(lookup[around] - i);
+		}
+
+		return pages;
 	}
 
 	const next = () => gotoChunk(lookup[reader.page] + 1);
-- 
cgit v1.2.3-2-gb3c3

