PaginationParameters is not working
bariscck opened this issue · comments
I am trying to fetch user's medias with PaginationParameter
.
If I set maxPageLoads
to 1, only fetching first page and nextMaxId
returns nil
.
If I set maxPageLoads
to 2, fetching 2 pages on first request and returns nextMaxId
but after that not fetching any data with this nextMaxId
.
Yes. Definitely a bug (PaginationHelper.swift:153
).
It actually returns the currently requested one on complete, instead of the next one.
I'm pushing a fix asap. @bariscck
I'll wait for the quick fix to the other PR and then push a new patch version. 💪
@sbertix thanks for the quick fix but this not fix this issue. I've tried your fixed code but nothing changes, still nextMaxId
returns nil
.
Forced push another try to sb/bugfixes
.
I've added currentMaxId
to PaginationParameters
too, just to avoid confusion in use cases.
Let me know if it works this way 😊 @bariscck
I'm accessing completionHandler
like this;
private var userFeedPagination: PaginationParameters?
private func fetchUserFeed(for pk: Int) {
var nextMaxId: String?
if let userFeedPagination = userFeedPagination {
nextMaxId = userFeedPagination.nextMaxId
}
let paginationParams = PaginationParameters(startingAt: nextMaxId)
dependency.handler.media.by(user: .primaryKey(pk), with: paginationParams, updateHandler: nil) {
[weak self] (result, pagination) in
switch result {
case .success(let medias):
print(pagination.nextMaxId)
print(pagination.canLoadMore)
self?.userFeedPagination = pagination
case .failure(let error):
print(error.localizedDescription)
}
}
}
Anything wrong with this code?
Nope. Looks absolutely fine to me 😊
Let me know if the new version actually works 🤞
It works like a charm! Thanks 😊But I think canLoadMore
is also broken because always returns false
.
Yeah canLoadMore
is one of the relics from 1.*
, that I didn't try to change too much when I wrote 2.*
.
It only holds whether you have reached the maximum amount of pages you set in the request or not.
No use for it being public
tbh, I'm definitely making it internal
.