Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Sep 25, 2023
1 parent 9a5c190 commit 89ff74e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Mlem/Models/Trackers/ContentTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,20 @@ class ContentTracker<Content: ContentModel>: 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")
Expand Down Expand Up @@ -135,8 +136,8 @@ class ContentTracker<Content: ContentModel>: 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 {
Expand Down

0 comments on commit 89ff74e

Please sign in to comment.