From bba89795a50656f0edae5a81fdf4b063b83741d3 Mon Sep 17 00:00:00 2001 From: Justin Edmund <383021+jedmund@users.noreply.github.com> Date: Tue, 23 Apr 2024 03:58:15 -0700 Subject: [PATCH] Add message when no teams were found --- hooks/useFetchTeams.tsx | 20 ++++++++++++-------- hooks/useTeamFilter.tsx | 8 +++++--- pages/teams.tsx | 15 ++++++++++++--- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/hooks/useFetchTeams.tsx b/hooks/useFetchTeams.tsx index 2a65677b..672986f2 100644 --- a/hooks/useFetchTeams.tsx +++ b/hooks/useFetchTeams.tsx @@ -9,7 +9,8 @@ export const useFetchTeams = ( setTotalPages: (value: number) => void, setRecordCount: (value: number) => void ) => { - const [isLoading, setIsLoading] = useState(false) + const [loaded, setLoaded] = useState(false) + const [fetching, setFetching] = useState(false) const [error, setError] = useState(false) function parseTeams(response: { [key: string]: any }, replace: boolean) { @@ -17,15 +18,17 @@ export const useFetchTeams = ( setTotalPages(meta.total_pages) setRecordCount(meta.count) + setLoaded(true) if (replace) { replaceResults(parties) - setIsLoading(false) + setFetching(false) } else appendResults(parties) } function parseError(error: any) { - setIsLoading(false) + setLoaded(true) + setFetching(false) setError(true) } @@ -62,7 +65,7 @@ export const useFetchTeams = ( const fetchTeams = useCallback( ({ replace } = { replace: false }) => { - if (replace) setIsLoading(true) + if (replace) setFetching(true) const params = createParams() @@ -89,7 +92,7 @@ export const useFetchTeams = ( username: string | undefined replace: boolean }) => { - if (replace) setIsLoading(true) + if (replace) setFetching(true) const params = createParams() @@ -115,7 +118,7 @@ export const useFetchTeams = ( const fetchSaved = useCallback( ({ replace } = { replace: false }) => { - if (replace) setIsLoading(true) + if (replace) setFetching(true) const params = createParams() @@ -139,8 +142,9 @@ export const useFetchTeams = ( fetchProfile, fetchSaved, processTeams, - isLoading, - setIsLoading, + loaded, + fetching, + setFetching, error, } } diff --git a/hooks/useTeamFilter.tsx b/hooks/useTeamFilter.tsx index 07866c5b..d918ae00 100644 --- a/hooks/useTeamFilter.tsx +++ b/hooks/useTeamFilter.tsx @@ -76,8 +76,9 @@ export const useTeamFilter = ( fetchProfile, fetchSaved, processTeams, - isLoading: isFetching, - setIsLoading: setFetching, + loaded, + fetching, + setFetching, error: fetchError, } = useFetchTeams( currentPage, @@ -168,7 +169,8 @@ export const useTeamFilter = ( setAdvancedFilters, parties, setParties, - isFetching, + loaded, + fetching, setFetching, fetchError, fetch, diff --git a/pages/teams.tsx b/pages/teams.tsx index 2be3e330..5b741154 100644 --- a/pages/teams.tsx +++ b/pages/teams.tsx @@ -32,6 +32,7 @@ import { CollectionPage } from '~utils/enums' interface Props { context?: PageContextObj + query: { [key: string]: string } version: AppUpdate error: boolean status?: ResponseStatus @@ -39,6 +40,7 @@ interface Props { const TeamsRoute: React.FC = ({ context, + query, version, error, status, @@ -63,7 +65,8 @@ const TeamsRoute: React.FC = ({ recordCount, parties, setParties, - isFetching, + loaded, + fetching, setFetching, fetchError, fetch, @@ -126,7 +129,7 @@ const TeamsRoute: React.FC = ({ goTo(party.shortcode)} onSave={(teamId, favorited) => toggleFavorite(teamId, favorited)} /> @@ -145,7 +148,12 @@ const TeamsRoute: React.FC = ({ const renderInfiniteScroll = ( <> - {parties.length === 0 && renderLoading(3)} + {parties.length === 0 && !loaded && renderLoading(3)} + {parties.length === 0 && loaded && ( +
+

There are no teams with your specified filters

+
+ )} 0 ? parties.length : 0} next={() => setCurrentPage(currentPage + 1)} @@ -204,6 +212,7 @@ export const getServerSideProps = async ({ req, res, locale, query }: { req: Nex return { props: { context: { raidGroups }, + query, version, error: false, ...(await serverSideTranslations(locale, ['common'])),