From 6bf1a60bbd19ecad48152037b294af0e80b6ee1d Mon Sep 17 00:00:00 2001 From: Keane Chan Date: Sun, 23 Oct 2022 01:01:34 +0800 Subject: [PATCH] [resumes][feat] show pagination only when required --- .../components/resumes/ResumeReviewsTitle.tsx | 2 +- .../resumes/browse/ResumeListItems.tsx | 13 +--- apps/portal/src/pages/resumes/browse.tsx | 68 +++++++++---------- 3 files changed, 36 insertions(+), 47 deletions(-) diff --git a/apps/portal/src/components/resumes/ResumeReviewsTitle.tsx b/apps/portal/src/components/resumes/ResumeReviewsTitle.tsx index 5e9cfda7..34c18c0a 100644 --- a/apps/portal/src/components/resumes/ResumeReviewsTitle.tsx +++ b/apps/portal/src/components/resumes/ResumeReviewsTitle.tsx @@ -3,7 +3,7 @@ import { Badge } from '@tih/ui'; export default function ResumeReviewsTitle() { return (
-

Resume Reviews

+

Resume Reviews

; }>; -export default function ResumeListItems({ isLoading, resumes }: Props) { - if (isLoading) { - return ( -
- -
- ); - } - +export default function ResumeListItems({ resumes }: Props) { return (
    {resumes.map((resumeObj: Resume) => ( diff --git a/apps/portal/src/pages/resumes/browse.tsx b/apps/portal/src/pages/resumes/browse.tsx index 4182fd63..a094fb5b 100644 --- a/apps/portal/src/pages/resumes/browse.tsx +++ b/apps/portal/src/pages/resumes/browse.tsx @@ -44,6 +44,8 @@ import { trpc } from '~/utils/trpc'; import type { FilterState } from '../../components/resumes/browse/resumeFilters'; +const STALE_TIME = 5 * 60 * 1000; +const DEBOUNCE_DELAY = 800; const PAGE_LIMIT = 10; const filters: Array = [ { @@ -122,14 +124,14 @@ export default function ResumeHomePage() { locationFilters: userFilters.location, numComments: userFilters.numComments, roleFilters: userFilters.role, - searchValue: useDebounceValue(searchValue, 800), + searchValue: useDebounceValue(searchValue, DEBOUNCE_DELAY), skip, sortOrder, }, ], { enabled: tabsValue === BROWSE_TABS_VALUES.ALL, - staleTime: 5 * 60 * 1000, + staleTime: STALE_TIME, }, ); const starredResumesQuery = trpc.useQuery( @@ -140,7 +142,7 @@ export default function ResumeHomePage() { locationFilters: userFilters.location, numComments: userFilters.numComments, roleFilters: userFilters.role, - searchValue: useDebounceValue(searchValue, 800), + searchValue: useDebounceValue(searchValue, DEBOUNCE_DELAY), skip, sortOrder, }, @@ -148,7 +150,7 @@ export default function ResumeHomePage() { { enabled: tabsValue === BROWSE_TABS_VALUES.STARRED, retry: false, - staleTime: 5 * 60 * 1000, + staleTime: STALE_TIME, }, ); const myResumesQuery = trpc.useQuery( @@ -159,7 +161,7 @@ export default function ResumeHomePage() { locationFilters: userFilters.location, numComments: userFilters.numComments, roleFilters: userFilters.role, - searchValue: useDebounceValue(searchValue, 800), + searchValue: useDebounceValue(searchValue, DEBOUNCE_DELAY), skip, sortOrder, }, @@ -167,7 +169,7 @@ export default function ResumeHomePage() { { enabled: tabsValue === BROWSE_TABS_VALUES.MY, retry: false, - staleTime: 5 * 60 * 1000, + staleTime: STALE_TIME, }, ); @@ -238,6 +240,11 @@ export default function ResumeHomePage() { : Math.floor(numRecords / PAGE_LIMIT) + 1; }; + const isFetchingResumes = + allResumesQuery.isFetching || + starredResumesQuery.isFetching || + myResumesQuery.isFetching; + return ( <> @@ -271,7 +278,7 @@ export default function ResumeHomePage() { leave="transition ease-in-out duration-300 transform" leaveFrom="translate-x-0" leaveTo="translate-x-full"> - +

    Shortcuts @@ -362,20 +369,20 @@ export default function ResumeHomePage() {

    -
    -
    +
    +
    -

    - Shortcuts: +

    + Shortcuts

      {SHORTCUTS.map((shortcut) => (
    • @@ -387,8 +394,8 @@ export default function ResumeHomePage() {
    • ))}
    -

    - Explore these filters: +

    + Explore these filters

    {filters.map((filter) => (
    - {allResumesQuery.isLoading || - starredResumesQuery.isLoading || - myResumesQuery.isLoading ? ( + {isFetchingResumes ? (
    {' '} {' '} @@ -553,23 +558,18 @@ export default function ResumeHomePage() {
    ) : ( <> - -
    - setCurrentPage(page)} - /> -
    + + {getTabTotalPages() > 1 && ( +
    + setCurrentPage(page)} + /> +
    + )} )}