Pagination offsets #239
-
Hello bro, I was upgrading my project with the latest changes you have done on the api, i can see that you changed how pagination works, now i use pages(count, offset) lets say i specified one page as count, and i want to add another page when i reach the last post only, how can i accomplish this? i tried incrementing pages , but posts will duplicate in this case. Can you help me out on this ? Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 21 replies
-
Hey @ramimoghrabi, Let's assume, for simplicity, you're fetching the first page of followers like this. let secret: Secret = /* a valid `Secret` */
var bin: Set<AnyCancellable> = /* a **retained** `Set` */
Endpoint.user(secret.identifier)
.followers
.unlock(with: secret)
.session(.instagram)
.pages(1)
.catch { _ in Empty() }
.sink {
// Do whatever you need to do with your response here…
guard let nextOffset = $0.offset else { return }
// If next offset is non-`nil`, you can just cache it or
// persist it somewhere.
}
.store(in: &bin) Now assuming you saved let nextOffset: String = /* a valid `String`, obtained like above */
let secret: Secret = /* a valid `Secret` */
var bin: Set<AnyCancellable> = /* a **retained** `Set` */
Endpoint.user(secret.identifier)
.followers
.unlock(with: secret)
.session(.instagram)
.pages(1, offset: nextOffset)
.catch { _ in Empty() }
.sink { _ in }
.store(in: &bin) |
Beta Was this translation helpful? Give feedback.
-
one more thing i wanted to know about timeline, that does not work as described above ? does it have another approach ? |
Beta Was this translation helpful? Give feedback.
-
i think there might be a bug , in comments offset, setting the offset on first fetch is always nil, thus it won't load since i used the above return method if not found : guard let nextOffset = $0.offset else { return } |
Beta Was this translation helpful? Give feedback.
-
hello again @sbertix ,i was wondering if you had time to check the comments pagination, as the wrapper.offset is always nil. |
Beta Was this translation helpful? Give feedback.
Hey @ramimoghrabi,
Let's assume, for simplicity, you're fetching the first page of followers like this.
Now assuming you saved
nextOffset
somewhere, when you need to load the second page of followers, you can ju…