1

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))
        }
    }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Peace Cloud
  • 43
  • 1
  • 6
  • "can't do it" is a bit unclear here. When you run this code in a debugger and step through it, what line doesn't do what you expect it to do? – Frank van Puffelen May 28 '20 at 18:49
  • Thank you Frank. I am sorry that I am just new at coding. The above code is working fine but cant paginate. I found the following article but I don't know where to make a change to achieve it. https://stackoverflow.com/a/61547188/11105245 – Peace Cloud May 28 '20 at 19:11
  • Teaching you how to build pagination is unfortunately a bit too broad for Stack Overflow. But the Firebase documentation should offer plenty of information to get started: https://firebase.google.com/docs/firestore/query-data/query-cursors – Frank van Puffelen May 28 '20 at 19:48
  • At least, could you tell me that I can achieve it with current code above or not? – Peace Cloud May 28 '20 at 20:26

0 Answers0