From e1aead3c5ee9d4742370f159ccf73dc1384b198c Mon Sep 17 00:00:00 2001 From: John Ballesteros Date: Mon, 19 Aug 2024 18:26:30 +0800 Subject: [PATCH 1/3] refactor: update grant fetch w/ default limit --- src/grants/data/get-grant-list.ts | 15 +++++++++++---- src/grants/data/get-grantee-list.ts | 4 +++- src/grants/hooks/use-grant-list-query.ts | 3 ++- src/grants/pages/grant-list-page.tsx | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/grants/data/get-grant-list.ts b/src/grants/data/get-grant-list.ts index 6889f92..cbe1f90 100644 --- a/src/grants/data/get-grant-list.ts +++ b/src/grants/data/get-grant-list.ts @@ -9,12 +9,19 @@ import { } from '@/grants/core/schemas'; import { dtoToGrant } from '@/grants/utils/dto-to-grant'; -export const getGrantList = async ( - page: number, +interface Props { + page: number; + searchParams?: string; + limit?: number; +} + +export const getGrantList = async ({ + page, searchParams = '', -): Promise => { + limit = Number(PAGE_SIZE) || 20, +}: Props): Promise => { const url = createUrlWithSearchParams( - `${grantQueryUrls.base}?page=${page}&limit=${PAGE_SIZE}`, + `${grantQueryUrls.base}?page=${page}&limit=${limit}`, searchParams, ); diff --git a/src/grants/data/get-grantee-list.ts b/src/grants/data/get-grantee-list.ts index 98177f3..06a0695 100644 --- a/src/grants/data/get-grantee-list.ts +++ b/src/grants/data/get-grantee-list.ts @@ -14,6 +14,7 @@ interface Props { page: number; searchParams?: string; grantId: string; + limit?: number; } // const data = fakeGrantees(); @@ -22,6 +23,7 @@ export const getGranteeList = async ({ page, grantId, searchParams = '', + limit = Number(PAGE_SIZE) || 20, }: Props): Promise => { // return { // page: page + 1, @@ -29,7 +31,7 @@ export const getGranteeList = async ({ // }; const url = createUrlWithSearchParams( - `${grantQueryUrls.grantees(grantId)}?page=${page}&limit=${PAGE_SIZE}&grantId=${grantId}`, + `${grantQueryUrls.grantees(grantId)}?page=${page}&limit=${limit}&grantId=${grantId}`, searchParams, ); diff --git a/src/grants/hooks/use-grant-list-query.ts b/src/grants/hooks/use-grant-list-query.ts index dcf0053..e9d8383 100644 --- a/src/grants/hooks/use-grant-list-query.ts +++ b/src/grants/hooks/use-grant-list-query.ts @@ -18,7 +18,8 @@ export const useGrantListQuery = () => { number >({ queryKey: grantQueryKeys.list(searchParams), - queryFn: async ({ pageParam }) => getGrantList(pageParam, searchParams), + queryFn: async ({ pageParam: page }) => + getGrantList({ page, searchParams }), initialPageParam: 1, getNextPageParam: ({ page, data }) => typeof page === 'number' && page > 0 && data.length > 0 diff --git a/src/grants/pages/grant-list-page.tsx b/src/grants/pages/grant-list-page.tsx index 856795c..ef22eac 100644 --- a/src/grants/pages/grant-list-page.tsx +++ b/src/grants/pages/grant-list-page.tsx @@ -16,7 +16,7 @@ export const GrantListPage = async () => { // Prefetch list queryClient.fetchInfiniteQuery({ queryKey: grantQueryKeys.list(''), - queryFn: async ({ pageParam }) => getGrantList(pageParam), + queryFn: async ({ pageParam: page }) => getGrantList({ page }), initialPageParam: 1, }), ]); From 522a5b99618f6ce1b13fc2414412d554122812a2 Mon Sep 17 00:00:00 2001 From: John Ballesteros Date: Mon, 19 Aug 2024 21:01:16 +0800 Subject: [PATCH 2/3] feat: statically generate grant routes --- src/app/grants/[grantId]/page.tsx | 17 +++++++++++++++++ src/shared/core/constants.ts | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/app/grants/[grantId]/page.tsx b/src/app/grants/[grantId]/page.tsx index 0762ed9..5fb40fe 100644 --- a/src/app/grants/[grantId]/page.tsx +++ b/src/app/grants/[grantId]/page.tsx @@ -1 +1,18 @@ +import { MAX_LIST_SIZE } from '@/shared/core/constants'; + +import { getGrantList } from '@/grants/data/get-grant-list'; + export { GranteeDetailsSection as default } from '@/grants/pages/grantee-details-section'; + +export const generateStaticParams = async () => { + const grantListResponse = await getGrantList({ + page: 1, + limit: MAX_LIST_SIZE, + }); + + const grantIds = Array.from( + new Set(grantListResponse.data.map((grant) => grant.id)), + ); + + return grantIds.map((grantId) => ({ grantId })); +}; diff --git a/src/shared/core/constants.ts b/src/shared/core/constants.ts index 6e89381..75b6184 100644 --- a/src/shared/core/constants.ts +++ b/src/shared/core/constants.ts @@ -61,3 +61,5 @@ export const TEST_IDS = { NAV_SECTION: 'nav-section', DETAILS_PANEL_TABS: 'details-panel-tabs', } as const; + +export const MAX_LIST_SIZE = 5000; From e14524cdf350eb7cdbbafb895497b7d023420688 Mon Sep 17 00:00:00 2001 From: John Ballesteros Date: Mon, 19 Aug 2024 21:05:17 +0800 Subject: [PATCH 3/3] ci: temp disable build step in github workflow --- .github/workflows/feature-branch.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index 301e008..361fde6 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -36,8 +36,8 @@ jobs: run: pnpm install - name: Run Lint run: pnpm lint - - name: Run Build - run: pnpm build + # - name: Run Build + # run: pnpm build - name: Run Test run: pnpm test