-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,58 @@ | ||
import { InView } from 'react-intersection-observer' | ||
|
||
import { type NextPage } from 'next' | ||
|
||
import { DeckCardList } from '~/components/deck-card-list' | ||
import { Loader } from '~/components/loader' | ||
import { api } from '~/utils/api' | ||
|
||
const Home: NextPage = () => { | ||
// TODO emiliosheinz: Add pagination | ||
const { isLoading, isError, data, refetch } = | ||
api.decks.getPublicDecks.useQuery({ | ||
page: 0, | ||
}) | ||
const { | ||
data, | ||
isError, | ||
refetch, | ||
isLoading, | ||
hasNextPage, | ||
fetchNextPage, | ||
isFetchingNextPage, | ||
} = api.decks.getPublicDecks.useInfiniteQuery( | ||
{}, | ||
{ | ||
getNextPageParam: lastPage => lastPage.nextCursor, | ||
refetchOnWindowFocus: false, | ||
keepPreviousData: true, | ||
}, | ||
) | ||
|
||
const decks = data?.pages.flatMap(page => page.decks) ?? [] | ||
const hasLoadedDecks = decks.length > 0 | ||
|
||
const renderContent = () => { | ||
if (isLoading) return <DeckCardList.Loading /> | ||
if (isError) return <DeckCardList.Error onRetryPress={refetch} /> | ||
|
||
return <DeckCardList decks={data} /> | ||
if (!hasLoadedDecks && isError) { | ||
return <DeckCardList.Error onRetryPress={refetch} /> | ||
} | ||
|
||
return <DeckCardList decks={decks} /> | ||
} | ||
|
||
return <div className='flex flex-col items-center'>{renderContent()}</div> | ||
return ( | ||
<div className='flex flex-col items-center'> | ||
{renderContent()} | ||
<InView | ||
as='div' | ||
className='mt-5 flex w-full items-center justify-center' | ||
onChange={inView => { | ||
if (inView && hasNextPage && !isError && !isFetchingNextPage) { | ||
fetchNextPage() | ||
} | ||
}} | ||
> | ||
{isFetchingNextPage ? <Loader /> : null} | ||
</InView> | ||
</div> | ||
) | ||
} | ||
|
||
export default Home |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65da981
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
briskly β ./
briskly-emiliosheinz.vercel.app
brisklyapp.vercel.app
briskly-git-main-emiliosheinz.vercel.app