Skip to content

Commit

Permalink
Merge pull request #165 from TheM4hd1/sb/bugfixes
Browse files Browse the repository at this point in the history
Fix `PaginationParameters` bug
  • Loading branch information
sbertix authored Apr 1, 2020
2 parents 16e85c6 + 67f766c commit e411c81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion SwiftyInsta/Helpers/PaginationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ class PaginationHelper: Handler {
options: options,
delay: delay,
process: process) { [weak self] in
// update the pagination parameters.
nextPaginationParameters.currentMaxId = nextPaginationParameters.nextMaxId
nextPaginationParameters.nextMaxId = nil
// check for handler.
guard let handler = self?.handler else {
return completion(.failure(GenericError.weakObjectReleased), nextPaginationParameters)
}
// deal with cases.
switch $0 {
case .failure(let error): completion(.failure(error), nextPaginationParameters)
case .success(let page):
nextPaginationParameters.nextMaxId = nextPage(page)
nextPaginationParameters.loadedPages += 1
// splice items.
let new = splice(page)
Expand All @@ -153,7 +158,6 @@ class PaginationHelper: Handler {
completion(.success(responses), nextPaginationParameters)
}
}
nextPaginationParameters.nextMaxId = nextPage(page)
guard !(nextPaginationParameters.nextMaxId ?? "").isEmpty else {
return handler.settings.queues.response.async {
completion(.success(responses), nextPaginationParameters)
Expand Down
4 changes: 3 additions & 1 deletion SwiftyInsta/Helpers/PaginationParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ public class PaginationParameters {
public var maxPagesToLoad: Int
/// The number of pages already loaded. Defaults to `0`.
public var loadedPages: Int = 0
/// The current request `maxId`. Defaults to `nil`.
public var currentMaxId: String?
/// The next `maxId`. Defaults to `nil`.
public var nextMaxId: String?

/// Whether there's something left to load.
public var canLoadMore: Bool { return loadedPages < maxPagesToLoad }
var canLoadMore: Bool { return loadedPages < maxPagesToLoad }

// MARK: Init
public init(startingAt maxId: String? = nil, maxPagesToLoad: Int = 1) {
Expand Down

0 comments on commit e411c81

Please sign in to comment.