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 all 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
9 changes: 8 additions & 1 deletion src/shared/components/community/community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,14 @@ export class Community extends Component<
</div>
{this.selects(res)}
{this.listings(res)}
<Paginator page={page} onChange={this.handlePageChange} />
<Paginator
page={page}
onChange={this.handlePageChange}
nextDisabled={
this.state.postsRes.state !== "success" ||
fetchLimit > this.state.postsRes.data.posts.length
}
/>
</main>
<aside className="d-none d-md-block col-md-4 col-lg-3">
{this.sidebar(res)}
Expand Down
6 changes: 5 additions & 1 deletion src/shared/components/home/emojis-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
{I18NextService.i18n.t("add_custom_emoji")}
</button>

<Paginator page={this.state.page} onChange={this.handlePageChange} />
<Paginator
page={this.state.page}
onChange={this.handlePageChange}
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 there never a time that this needs to be disabled?

Copy link
Member

Choose a reason for hiding this comment

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

It needs to be disabled when there are multiple lists (because the API doesn't combine them)

/>
</div>
</div>
);
Expand Down
9 changes: 8 additions & 1 deletion src/shared/components/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,14 @@ export class Home extends Component<any, HomeState> {
<div>
{this.selects}
{this.listings}
<Paginator page={page} onChange={this.handlePageChange} />
<Paginator
page={page}
onChange={this.handlePageChange}
nextDisabled={
this.state.postsRes?.state !== "success" ||
fetchLimit > this.state.postsRes.data.posts.length
}
/>
</div>
</div>
);
Expand Down
6 changes: 5 additions & 1 deletion src/shared/components/modlog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,11 @@ export class Modlog extends Component<
</thead>
{this.combined}
</table>
<Paginator page={page} onChange={this.handlePageChange} />
<Paginator
page={page}
onChange={this.handlePageChange}
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.

Same here.

/>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/components/person/inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export class Inbox extends Component<any, InboxState> {
<Paginator
page={this.state.page}
onChange={this.handlePageChange}
nextDisabled={false}
/>
</div>
</div>
Expand Down
11 changes: 10 additions & 1 deletion src/shared/components/person/person-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ export class PersonDetails extends Component<PersonDetailsProps, any> {
<div className="person-details">
{this.viewSelector(this.props.view)}

<Paginator page={this.props.page} onChange={this.handlePageChange} />
<Paginator
page={this.props.page}
onChange={this.handlePageChange}
nextDisabled={
(this.props.view === PersonDetailsView.Comments &&
this.props.limit > this.props.personRes.comments.length) ||
(this.props.view === PersonDetailsView.Posts &&
this.props.limit > this.props.personRes.posts.length)
}
/>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class RegistrationApplications extends Component<
<Paginator
page={this.state.page}
onChange={this.handlePageChange}
nextDisabled={fetchLimit > apps.length}
/>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions src/shared/components/person/reports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ export class Reports extends Component<any, ReportsState> {
<Paginator
page={this.state.page}
onChange={this.handlePageChange}
nextDisabled={
(this.state.messageType === MessageType.All &&
fetchLimit > this.buildCombined.length) ||
(this.state.messageType === MessageType.CommentReport &&
fetchLimit > this.commentReports.length) ||
(this.state.messageType === MessageType.PostReport &&
fetchLimit > this.postReports.length) ||
(this.state.messageType === MessageType.PrivateMessageReport &&
fetchLimit > this.privateMessageReports.length)
}
/>
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/shared/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,14 @@ export class Search extends Component<any, SearchState> {
this.state.searchRes.state === "success" && (
<span>{I18NextService.i18n.t("no_results")}</span>
)}
<Paginator page={page} onChange={this.handlePageChange} />
<Paginator
page={page}
onChange={this.handlePageChange}
nextDisabled={
this.state.searchRes.state !== "success" ||
fetchLimit > this.resultsCount
}
/>
</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:
* !community@server.com
Expand Down