Skip to content

Commit

Permalink
Merge pull request stakwork#500 from aliraza556/Load-More-Bounties-on…
Browse files Browse the repository at this point in the history
…-Assigned-and-Bounties-Pages

[FIX] Issues with "Load More" Functionality and Button Visibility on Assigned and Bounties Pages
  • Loading branch information
elraphty authored Apr 27, 2024
2 parents 9091a60 + 442400a commit 08681bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/pages/people/tabs/Wanted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(() => {
Expand Down
11 changes: 7 additions & 4 deletions src/people/widgetViews/UserTicketsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const UserTickets = () => {

const defaultStatus: Record<string, boolean> = {
Assigned: false,
Open: false
Paid: false
};

const [checkboxIdToSelectedMap, setCheckboxIdToSelectedMap] = useState(defaultStatus);
Expand Down Expand Up @@ -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;
Expand All @@ -133,7 +136,7 @@ const UserTickets = () => {
if (response.length < paginationLimit) {
setHasMoreBounties(false);
}
setDisplayedBounties(response);
setDisplayedBounties((prevBounties: BountyType[]) => [...prevBounties, ...response]);
};

useEffect(() => {
Expand Down

0 comments on commit 08681bb

Please sign in to comment.