-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: profile proposals pagination (#1384)
* fix: profile proposals pagination * fix: empty state * feat: add isFetching check in view more button
- Loading branch information
Showing
12 changed files
with
202 additions
and
187 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { CoauthorAttributes } from '../../entities/Coauthor/types' | ||
import useFormatMessage from '../../hooks/useFormatMessage' | ||
import useInfiniteProposals from '../../hooks/useInfiniteProposals' | ||
import { UseProposalsFilter } from '../../hooks/useProposals' | ||
import Empty from '../Common/Empty' | ||
import FullWidthButton from '../Common/FullWidthButton' | ||
import SkeletonBars from '../Common/SkeletonBars' | ||
import Watermelon from '../Icon/Watermelon' | ||
|
||
import ProposalCreatedItem from './ProposalCreatedItem' | ||
|
||
interface Props { | ||
proposalsFilter: Partial<UseProposalsFilter> | ||
pendingCoauthorRequests?: CoauthorAttributes[] | ||
emptyDescriptionText: string | ||
showCoauthoring?: boolean | ||
} | ||
|
||
export function ProposalCreatedList({ | ||
proposalsFilter, | ||
pendingCoauthorRequests, | ||
emptyDescriptionText, | ||
showCoauthoring = false, | ||
}: Props) { | ||
const t = useFormatMessage() | ||
const { proposals, isLoadingProposals, isFetchingNextPage, isFetchingProposals, hasMoreProposals, loadMore } = | ||
useInfiniteProposals(proposalsFilter) | ||
const hasProposals = proposals && proposals?.[0]?.total > 0 | ||
|
||
return ( | ||
<> | ||
{isLoadingProposals && <SkeletonBars amount={3} height={89} />} | ||
{!isLoadingProposals && ( | ||
<> | ||
{hasProposals ? ( | ||
proposals.map((page) => | ||
page.data.map((proposal) => ( | ||
<ProposalCreatedItem | ||
key={proposal.id} | ||
proposal={proposal} | ||
showCoauthoring={showCoauthoring} | ||
hasCoauthorRequests={!!pendingCoauthorRequests?.find((req) => req.proposal_id === proposal.id)} | ||
/> | ||
)) | ||
) | ||
) : ( | ||
<Empty className="ActivityBox__Empty" icon={<Watermelon />} description={emptyDescriptionText} /> | ||
)} | ||
{hasMoreProposals && ( | ||
<FullWidthButton loading={isFetchingNextPage || isFetchingProposals} onClick={loadMore}> | ||
{t('page.profile.activity.button')} | ||
</FullWidthButton> | ||
)} | ||
</> | ||
)} | ||
</> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useInfiniteQuery } from '@tanstack/react-query' | ||
|
||
import { DEFAULT_QUERY_STALE_TIME } from './constants' | ||
import { UseProposalsFilter, getProposalsQueryFn } from './useProposals' | ||
|
||
const DEFAULT_ITEMS_PER_PAGE = 5 | ||
|
||
export default function useInfiniteProposals(filter: Partial<UseProposalsFilter> = {}) { | ||
const { | ||
data: proposals, | ||
isLoading: isLoadingProposals, | ||
isFetching: isFetchingProposals, | ||
fetchNextPage, | ||
hasNextPage, | ||
isFetchingNextPage, | ||
} = useInfiniteQuery({ | ||
queryKey: [`infinite-proposals#${JSON.stringify(filter)}`], | ||
queryFn: getProposalsQueryFn(filter, DEFAULT_ITEMS_PER_PAGE), | ||
staleTime: DEFAULT_QUERY_STALE_TIME, | ||
getNextPageParam: (lastPage, pages) => { | ||
const fetchedTotal = pages.reduce((acc, currentValue) => acc + currentValue.data.length, 0) | ||
return lastPage.total > fetchedTotal ? pages.length : undefined | ||
}, | ||
}) | ||
|
||
return { | ||
proposals: proposals?.pages, | ||
isLoadingProposals, | ||
isFetchingProposals, | ||
isFetchingNextPage, | ||
hasMoreProposals: !!hasNextPage, | ||
loadMore: fetchNextPage, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.