From 442400a0f1d761e9448e09a477745820a58f9539 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Sat, 27 Apr 2024 17:44:33 +0500 Subject: [PATCH] Fix Load More Functionality and Button Visibility on Assigned and Bounties Pages --- src/pages/people/tabs/Wanted.tsx | 10 ++++++---- src/people/widgetViews/UserTicketsView.tsx | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pages/people/tabs/Wanted.tsx b/src/pages/people/tabs/Wanted.tsx index b3b7f0ba..891b388a 100644 --- a/src/pages/people/tabs/Wanted.tsx +++ b/src/pages/people/tabs/Wanted.tsx @@ -73,21 +73,23 @@ export const Wanted = observer(() => { // Function to fetch user tickets with pagination const getUserTickets = useCallback(async () => { setIsLoading(true); - + setPage(1); // Fetch bounties for the specified page and limit const response = await main.getPersonCreatedBounties( - { page: page, limit: paginationQueryLimit, sortBy: 'created', ...checkboxIdToSelectedMap }, + { page: 1, limit: paginationQueryLimit, sortBy: 'created', ...checkboxIdToSelectedMap }, uuid ); // Check if the response has fewer bounties than the limit, indicating no more bounties to load if (response.length < paginationQueryLimit) { setHasMoreBounties(false); + } else { + setHasMoreBounties(true); } // Update the displayed bounties by appending the new bounties setDisplayedBounties(response); setIsLoading(false); - }, [checkboxIdToSelectedMap, main, page, uuid]); + }, [main, uuid, checkboxIdToSelectedMap]); const nextBounties = async () => { const nextPage = page + 1; @@ -102,7 +104,7 @@ export const Wanted = observer(() => { setHasMoreBounties(false); } // Update the displayed bounties by appending the new bounties - setDisplayedBounties(response); + setDisplayedBounties((prevBounties: BountyType[]) => [...prevBounties, ...response]); }; useEffect(() => { diff --git a/src/people/widgetViews/UserTicketsView.tsx b/src/people/widgetViews/UserTicketsView.tsx index 84516919..f26aaa80 100644 --- a/src/people/widgetViews/UserTicketsView.tsx +++ b/src/people/widgetViews/UserTicketsView.tsx @@ -65,7 +65,7 @@ const UserTickets = () => { const defaultStatus: Record = { Assigned: false, - Open: false + Paid: false }; const [checkboxIdToSelectedMap, setCheckboxIdToSelectedMap] = useState(defaultStatus); @@ -112,16 +112,19 @@ const UserTickets = () => { const getUserTickets = useCallback(async () => { setIsLoading(true); + setPage(1); const response = await main.getPersonAssignedBounties( - { page: page, limit: paginationLimit, ...checkboxIdToSelectedMap }, + { page: 1, limit: paginationLimit, ...checkboxIdToSelectedMap }, uuid ); if (response.length < paginationLimit) { setHasMoreBounties(false); + } else { + setHasMoreBounties(true); } setDisplayedBounties(response); setIsLoading(false); - }, [main, page, uuid, checkboxIdToSelectedMap]); + }, [main, uuid, checkboxIdToSelectedMap]); const nextBounties = async () => { const nextPage = page + 1; @@ -133,7 +136,7 @@ const UserTickets = () => { if (response.length < paginationLimit) { setHasMoreBounties(false); } - setDisplayedBounties(response); + setDisplayedBounties((prevBounties: BountyType[]) => [...prevBounties, ...response]); }; useEffect(() => {