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

feat: static grant routes #104

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .github/workflows/feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions src/app/grants/[grantId]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 }));
};
15 changes: 11 additions & 4 deletions src/grants/data/get-grant-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GrantInfiniteListPage> => {
limit = Number(PAGE_SIZE) || 20,
}: Props): Promise<GrantInfiniteListPage> => {
const url = createUrlWithSearchParams(
`${grantQueryUrls.base}?page=${page}&limit=${PAGE_SIZE}`,
`${grantQueryUrls.base}?page=${page}&limit=${limit}`,
searchParams,
);

Expand Down
4 changes: 3 additions & 1 deletion src/grants/data/get-grantee-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props {
page: number;
searchParams?: string;
grantId: string;
limit?: number;
}

// const data = fakeGrantees();
Expand All @@ -22,14 +23,15 @@ export const getGranteeList = async ({
page,
grantId,
searchParams = '',
limit = Number(PAGE_SIZE) || 20,
}: Props): Promise<GranteeInfiniteListPage> => {
// return {
// page: page + 1,
// data,
// };

const url = createUrlWithSearchParams(
`${grantQueryUrls.grantees(grantId)}?page=${page}&limit=${PAGE_SIZE}&grantId=${grantId}`,
`${grantQueryUrls.grantees(grantId)}?page=${page}&limit=${limit}&grantId=${grantId}`,
searchParams,
);

Expand Down
3 changes: 2 additions & 1 deletion src/grants/hooks/use-grant-list-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/grants/pages/grant-list-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
]);
Expand Down
2 changes: 2 additions & 0 deletions src/shared/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading