MCPcopy Create free account
hub / github.com/coder/coder / onPageChange

Function onPageChange

site/src/hooks/usePaginatedQuery.ts:263–282  ·  view source on GitHub ↗
(newPage: number)

Source from the content-addressed store, hash-verified

261 }, [query.isFetching, totalPages, currentPage]);
262
263 const onPageChange = (newPage: number) => {
264 // Page 1 is the only page that can be safely navigated to without knowing
265 // totalPages; no reliance on server data for math calculations
266 if (totalPages === undefined && newPage !== 1) {
267 return;
268 }
269
270 // If the true count is unknown, we allow navigating past the
271 // known page range.
272 const upperBound = countIsCapped
273 ? Number.MAX_SAFE_INTEGER
274 : (totalPages ?? 1);
275 const cleanedInput = clamp(Math.trunc(newPage), 1, upperBound);
276 if (Number.isNaN(cleanedInput)) {
277 return;
278 }
279
280 searchParams.set(PAGE_NUMBER_PARAMS_KEY, String(cleanedInput));
281 setSearchParams(searchParams);
282 };
283
284 // Have to do a type assertion for final return type to make React Query's
285 // internal types happy; splitting type definitions up to limit risk of the

Callers 3

PaginationWidgetBaseFunction · 0.85
WorkspacesPageViewFunction · 0.85
usePaginatedQueryFunction · 0.85

Calls 3

clampFunction · 0.85
StringFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected