Skip to content

Commit faff408

Browse files
Merge pull request #301 from IntersectMBO/feat/Implement-Infinite-Scroll-for-Budget-Proposals-Section-(3697)
feat: Implement infinite scrolling for Budget Discussions List
2 parents 2d0b964 + bcb685d commit faff408

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

pdf-ui/src/components/BudgetDiscussionsList/index.jsx

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const BudgetDiscussionsList = ({
4242
}) => {
4343
const theme = useTheme();
4444
const sliderRef = useRef(null);
45+
const observer = useRef();
4546

4647
const [showAll, setShowAll] = useState(false);
4748
const [budgetDiscussionList, setBudgetDiscussionList] = useState([]);
@@ -208,6 +209,24 @@ const BudgetDiscussionsList = ({
208209
setIsAllProposalsListEmpty,
209210
]);
210211

212+
const lastBudgetProposalRef = useCallback(
213+
(node) => {
214+
if (observer.current) observer.current.disconnect();
215+
observer.current = new window.IntersectionObserver((entries) => {
216+
if (
217+
entries[0].isIntersecting &&
218+
currentPage < pageCount &&
219+
budgetDiscussionList.length > 0
220+
) {
221+
fetchBudgetDiscussions(false, currentPage + 1);
222+
setCurrentPage((prev) => prev + 1);
223+
}
224+
});
225+
if (node) observer.current.observe(node);
226+
},
227+
[currentPage, pageCount, budgetDiscussionList.length]
228+
);
229+
211230
return budgetDiscussionList?.length === 0 ? null : (
212231
<Box overflow={'visible'}>
213232
<Box
@@ -293,21 +312,38 @@ const BudgetDiscussionsList = ({
293312
) ? (
294313
<Box>
295314
<Grid container spacing={4} paddingY={4}>
296-
{budgetDiscussionList?.map((bd, index) => (
297-
<Grid item key={index} xs={12} sm={6} md={4}>
298-
<BudgetDiscussionsCard
299-
budgetDiscussion={bd}
300-
isDraft={isDraft}
301-
startEdittingDraft={startEdittingDraft}
302-
startEdittinButtonClick={
303-
startEdittinButtonClick
315+
{budgetDiscussionList?.map((bd, index) => {
316+
const isLast =
317+
index === budgetDiscussionList.length - 1;
318+
return (
319+
<Grid
320+
item
321+
key={index}
322+
xs={12}
323+
sm={6}
324+
md={4}
325+
ref={
326+
isLast
327+
? lastBudgetProposalRef
328+
: null
304329
}
305-
/>
306-
</Grid>
307-
))}
330+
>
331+
<BudgetDiscussionsCard
332+
budgetDiscussion={bd}
333+
isDraft={isDraft}
334+
startEdittingDraft={
335+
startEdittingDraft
336+
}
337+
startEdittinButtonClick={
338+
startEdittinButtonClick
339+
}
340+
/>
341+
</Grid>
342+
);
343+
})}
308344
</Grid>
309345

310-
{currentPage < pageCount && (
346+
{/* {currentPage < pageCount && (
311347
<Box
312348
marginY={2}
313349
display={'flex'}
@@ -325,7 +361,7 @@ const BudgetDiscussionsList = ({
325361
Load more
326362
</Button>
327363
</Box>
328-
)}
364+
)} */}
329365
</Box>
330366
) : (
331367
<Box py={2}>

pdf-ui/src/components/ProposalsList/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ const ProposalsList = ({
106106
} else {
107107
setProposalsList((prev) => [...prev, ...proposals]);
108108
}
109-
console.log('🚀 ~ fetchProposals ~ proposals:', proposals);
110109
setPageCount(pgCount);
111110
} catch (error) {
112111
console.error(error);

0 commit comments

Comments
 (0)