|
5 | 5 | MeetingRoom, |
6 | 6 | } from "@mui/icons-material"; |
7 | 7 | import { Box, IconButton, styled, Typography } from "@mui/material"; |
8 | | -import { useQuery } from "@tanstack/react-query"; |
| 8 | +import { useInfiniteQuery } from "@tanstack/react-query"; |
9 | 9 | import Alert from "components/Alert"; |
10 | 10 | import FadingScrollTrack from "components/FadingScrollTrack"; |
11 | 11 | import { hostRequestsListKey } from "features/queryKeys"; |
@@ -217,34 +217,46 @@ export default function UpcomingStays() { |
217 | 217 | data: tripsData, |
218 | 218 | isLoading: tripsLoading, |
219 | 219 | error: tripsError, |
220 | | - } = useQuery<ListHostRequestsRes.AsObject, RpcError>({ |
221 | | - queryKey: hostRequestsListKey({ type: "surfing" }), |
222 | | - queryFn: () => |
| 220 | + } = useInfiniteQuery<ListHostRequestsRes.AsObject, RpcError>({ |
| 221 | + queryKey: hostRequestsListKey({ type: "surfing", onlyActive: true }), |
| 222 | + queryFn: ({ pageParam }) => |
223 | 223 | service.requests.listHostRequests({ |
| 224 | + pageToken: pageParam as string | undefined, |
224 | 225 | type: "surfing", |
225 | 226 | onlyActive: true, |
226 | 227 | statusIn: UPCOMING_STATUSES, |
227 | 228 | sortBy: HostRequestSortBy.HOST_REQUEST_SORT_BY_FROM_DATE, |
228 | 229 | }), |
| 230 | + initialPageParam: undefined, |
| 231 | + getNextPageParam: (lastPage) => |
| 232 | + lastPage.noMore ? undefined : lastPage.nextPageToken, |
229 | 233 | }); |
230 | 234 |
|
231 | 235 | const { |
232 | 236 | data: guestsData, |
233 | 237 | isLoading: guestsLoading, |
234 | 238 | error: guestsError, |
235 | | - } = useQuery<ListHostRequestsRes.AsObject, RpcError>({ |
236 | | - queryKey: hostRequestsListKey({ type: "hosting" }), |
237 | | - queryFn: () => |
| 239 | + } = useInfiniteQuery<ListHostRequestsRes.AsObject, RpcError>({ |
| 240 | + queryKey: hostRequestsListKey({ type: "hosting", onlyActive: true }), |
| 241 | + queryFn: ({ pageParam }) => |
238 | 242 | service.requests.listHostRequests({ |
| 243 | + pageToken: pageParam as string | undefined, |
239 | 244 | type: "hosting", |
240 | 245 | onlyActive: true, |
241 | 246 | statusIn: UPCOMING_STATUSES, |
242 | 247 | sortBy: HostRequestSortBy.HOST_REQUEST_SORT_BY_FROM_DATE, |
243 | 248 | }), |
| 249 | + initialPageParam: undefined, |
| 250 | + getNextPageParam: (lastPage) => |
| 251 | + lastPage.noMore ? undefined : lastPage.nextPageToken, |
244 | 252 | }); |
245 | 253 |
|
246 | | - const upcomingTrips = tripsData?.hostRequestsList ?? []; |
247 | | - const upcomingGuests = guestsData?.hostRequestsList ?? []; |
| 254 | + const upcomingTrips = (tripsData?.pages ?? []).flatMap( |
| 255 | + (page) => page.hostRequestsList, |
| 256 | + ); |
| 257 | + const upcomingGuests = (guestsData?.pages ?? []).flatMap( |
| 258 | + (page) => page.hostRequestsList, |
| 259 | + ); |
248 | 260 |
|
249 | 261 | const error = tripsError ?? guestsError; |
250 | 262 |
|
|
0 commit comments