From 589c8abd4ac94331f3d261b5a253b08c9e87a810 Mon Sep 17 00:00:00 2001 From: GabrielTomonariDev Date: Mon, 7 Feb 2022 17:56:08 -0300 Subject: [PATCH] Add missing previous function in pagination snippet --- firestore-next/test.firestore.js | 11 +++++++++++ snippets/firestore-next/test-firestore/paginate.js | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 71c54b95..4eeea2d5 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1088,6 +1088,17 @@ describe("firestore", () => { orderBy("population"), startAfter(lastVisible), limit(25)); + + // Get the first visible document + const firstVisible = documentSnapshots.docs[0]; + console.log("first", firstVisible); + + // Construct a new query starting at this document, + // get the previous 25 cities. + const previous = query(collection(db, "cities"), + orderBy("population"), + endBefore(lastVisible), + limitToLast(25)); // [END paginate] }); }); diff --git a/snippets/firestore-next/test-firestore/paginate.js b/snippets/firestore-next/test-firestore/paginate.js index cdc146ca..1aa61257 100644 --- a/snippets/firestore-next/test-firestore/paginate.js +++ b/snippets/firestore-next/test-firestore/paginate.js @@ -21,4 +21,15 @@ const next = query(collection(db, "cities"), orderBy("population"), startAfter(lastVisible), limit(25)); + +// Get the first visible document +const firstVisible = documentSnapshots.docs[0]; +console.log("first", firstVisible); + +// Construct a new query starting at this document, +// get the previous 25 cities. +const previous = query(collection(db, "cities"), + orderBy("population"), + endBefore(lastVisible), + limitToLast(25)); // [END paginate_modular] \ No newline at end of file