Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable "Next" button in Paginator when the next page is empty #2114

Merged
merged 14 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/shared/components/common/paginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { I18NextService } from "../../services";
interface PaginatorProps {
page: number;
onChange(val: number): any;
nextDisabled?: boolean;
}

export class Paginator extends Component<PaginatorProps, any> {
Expand All @@ -23,6 +24,7 @@ export class Paginator extends Component<PaginatorProps, any> {
<button
className="btn btn-secondary"
onClick={linkEvent(this, this.handleNext)}
disabled={this.props.nextDisabled || false}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the || false necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, it's a residue after nextDisabled was optional to not pass "undefined" to the property, I'll fix it

>
{I18NextService.i18n.t("next")}
</button>
Expand Down
11 changes: 9 additions & 2 deletions src/shared/components/community/communities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { Paginator } from "../common/paginator";
import { SortSelect } from "../common/sort-select";
import { CommunityLink } from "./community-link";

const communityLimit = 50;
import { communityLimit } from "../../config";

type CommunitiesData = RouteDataResponse<{
listCommunitiesResponse: ListCommunitiesResponse;
Expand Down Expand Up @@ -221,7 +221,14 @@ export class Communities extends Component<any, CommunitiesState> {
</tbody>
</table>
</div>
<Paginator page={page} onChange={this.handlePageChange} />
<Paginator
page={page}
onChange={this.handlePageChange}
nextDisabled={
communityLimit >
this.state.listCommunitiesResponse.data.communities.length
dessalines marked this conversation as resolved.
Show resolved Hide resolved
}
/>
</div>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const relTags = "noopener nofollow";
export const emDash = "\u2014";
export const authCookieName = "jwt";

// No. of max displayed communities per
// page on route "/communities"
export const communityLimit = 50;

/**
* Accepted formats:
* [email protected]
Expand Down