I want to paginate my query with Firestore (Firesnapshot and Resiwft). I just don't find a way or can't do it as it is described in the google documents.
case updatePosts(userID: String, posts: [Snapshot<Model.Post>])
case updateListener(userID: String, listener: ListenerRegistration?)
static func subscribe(userID: String) -> AppThunkAction {
AppThunkAction { dispatch, _ in
let listener = Snapshot<Model.Post>.listen(.posts(userID: userID), queryBuilderBlock: { snapshot in
snapshot.order(by: .createTime, descending: true)
.where(\.isRemoved == false)
.limit(to: 3)
}) { result in
switch result {
case let .success(posts):
dispatch(FollowingPostsAction.updatePosts(userID: userID, posts: posts))
case let .failure(error):
print(error)
// error handling
dispatch(FollowingPostsAction.updatePosts(userID: userID, posts: []))
}
}
dispatch(FollowingPostsAction.updateListener(userID: userID, listener: listener))
}
}