Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding pagination to bill index page #275

Merged
merged 7 commits into from
Mar 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
handle partial last pages and falsey keys
  • Loading branch information
alexjball committed Mar 8, 2022
commit c9c73e070d1ccd73bf0d5e867a4f8702090f3e58
6 changes: 3 additions & 3 deletions components/db/bills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Timestamp,
where
} from "firebase/firestore"
import { last } from "lodash"
import { nth } from "lodash"
import { useMemo, useReducer } from "react"
import { useAsync } from "react-async-hook"
import { firestore } from "../firebase"
Expand Down Expand Up @@ -101,7 +101,7 @@ function reducer(state: State, action: Action): State {
return { ...state, billId: action.billId, ...initialPage }
} else if (action.type === "onSuccess") {
const keys = [...state.pageKeys]
const bill = last(action.page)
const bill = nth(action.page, state.billsPerPage - 1)
keys[state.currentPage + 1] =
bill !== undefined ? getPageKey(bill, state.sort) : undefined
return {
Expand Down Expand Up @@ -248,7 +248,7 @@ async function listBills(
if (billId) constraints.push(where("id", "==", billId))
constraints.push(orderBy(...getOrderBy(sort)))
constraints.push(limit(limitCount))
if (startAfterKey) constraints.push(startAfter(startAfterKey))
if (startAfterKey !== null) constraints.push(startAfter(startAfterKey))

const result = await getDocs(query(billsRef, ...constraints))
return result.docs.map(d => d.data() as Bill)
Expand Down