From 89ff74e233e56a437ea4190927e40562d225884c Mon Sep 17 00:00:00 2001 From: Sjmarf <78750526+Sjmarf@users.noreply.github.com> Date: Mon, 25 Sep 2023 21:29:24 +0100 Subject: [PATCH] Bug fix --- Mlem/Models/Trackers/ContentTracker.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Mlem/Models/Trackers/ContentTracker.swift b/Mlem/Models/Trackers/ContentTracker.swift index 96093b859..adba5ee26 100644 --- a/Mlem/Models/Trackers/ContentTracker.swift +++ b/Mlem/Models/Trackers/ContentTracker.swift @@ -91,19 +91,20 @@ class ContentTracker: ObservableObject { /// Load the next page of results. Calls the `loadItems` attribute of the tracker, which returns an array of ContentType items. func loadNextPage() async throws { + let newPage = self.page + 1 RunLoop.main.perform { [self] in isLoading = true - page += 1 } currentTask = Task(priority: .userInitiated) { [self] in do { - let newItems = try await self.loadItems(page) + let newItems = try await self.loadItems(newPage) RunLoop.main.perform { [self] in self.items.append(contentsOf: loadItems(newItems)) self.isLoading = false if newItems.isEmpty { hasReachedEnd = true } + self.page = newPage } } catch is CancellationError { print("Page loading cancelled") @@ -135,8 +136,8 @@ class ContentTracker: ObservableObject { } /// Prepares items to be added to the tracker by preloading images and removing duplicates - func loadItems(_ newItems: [Content]) -> [Content] { - let newItems = newItems.filter { ids.insert($0.uid).inserted } + func loadItems(_ items: [Content]) -> [Content] { + let newItems = items.filter { ids.insert($0.uid).inserted } var imageRequests: [ImageRequest] = [] URLSession.shared.configuration.urlCache = AppConstants.urlCache for item in newItems {