setOptionalAuth,
} from "../utils";
import { CommunityLink } from "./community-link";
+import { Paginator } from "./paginator";
import { Spinner } from "./icon";
import { i18n } from "../i18next";
import { InitialFetchRequest } from "shared/interfaces";
constructor(props: any, context: any) {
super(props, context);
this.state = this.emptyState;
+ this.handlePageChange = this.handlePageChange.bind(this);
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
</tbody>
</table>
</div>
- {this.paginator()}
+ <Paginator
+ page={this.state.page}
+ onChange={this.handlePageChange}
+ />
</div>
)}
</div>
);
}
- paginator() {
- return (
- <div class="mt-2">
- {this.state.page > 1 && (
- <button
- class="btn btn-secondary mr-1"
- onClick={linkEvent(this, this.prevPage)}
- >
- {i18n.t("prev")}
- </button>
- )}
-
- {this.state.communities.length > 0 && (
- <button
- class="btn btn-secondary"
- onClick={linkEvent(this, this.nextPage)}
- >
- {i18n.t("next")}
- </button>
- )}
- </div>
- );
- }
-
updateUrl(paramUpdates: CommunitiesProps) {
const page = paramUpdates.page || this.state.page;
this.props.history.push(`/communities/page/${page}`);
}
- nextPage(i: Communities) {
- i.updateUrl({ page: i.state.page + 1 });
- }
-
- prevPage(i: Communities) {
- i.updateUrl({ page: i.state.page - 1 });
+ handlePageChange(page: number) {
+ this.updateUrl({ page });
}
handleUnsubscribe(communityId: number) {
-import { Component, linkEvent } from "inferno";
+import { Component } from "inferno";
import { Subscription } from "rxjs";
import { DataType, InitialFetchRequest } from "../interfaces";
import {
import { CommunityLink } from "./community-link";
import { BannerIconHeader } from "./banner-icon-header";
import { Icon, Spinner } from "./icon";
+import { Paginator } from "./paginator";
import {
wsJsonToRes,
fetchLimit,
this.state = this.emptyState;
this.handleSortChange = this.handleSortChange.bind(this);
this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
+ this.handlePageChange = this.handlePageChange.bind(this);
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
{this.communityInfo()}
{this.selects()}
{this.listings()}
- {this.paginator()}
+ <Paginator
+ page={this.state.page}
+ onChange={this.handlePageChange}
+ />
</div>
<div class="col-12 col-md-4">
<Sidebar
);
}
- paginator() {
- return (
- <div class="my-2">
- {this.state.page > 1 && (
- <button
- class="btn btn-secondary mr-1"
- onClick={linkEvent(this, this.prevPage)}
- >
- {i18n.t("prev")}
- </button>
- )}
- {this.state.posts.length > 0 && (
- <button
- class="btn btn-secondary"
- onClick={linkEvent(this, this.nextPage)}
- >
- {i18n.t("next")}
- </button>
- )}
- </div>
- );
- }
-
- nextPage(i: Community) {
- i.updateUrl({ page: i.state.page + 1 });
- window.scrollTo(0, 0);
- }
-
- prevPage(i: Community) {
- i.updateUrl({ page: i.state.page - 1 });
+ handlePageChange(page: number) {
+ this.updateUrl({ page });
window.scrollTo(0, 0);
}
import { CommentNodes } from "./comment-nodes";
import { PrivateMessage } from "./private-message";
import { HtmlTags } from "./html-tags";
+import { Paginator } from "./paginator";
import { SortSelect } from "./sort-select";
import { Icon, Spinner } from "./icon";
import { i18n } from "../i18next";
this.state = this.emptyState;
this.handleSortChange = this.handleSortChange.bind(this);
+ this.handlePageChange = this.handlePageChange.bind(this);
if (!UserService.Instance.localUserView && isBrowser()) {
toast(i18n.t("not_logged_in"), "danger");
this.mentions()}
{this.state.messageType == MessageType.Messages &&
this.messages()}
- {this.paginator()}
+ <Paginator
+ page={this.state.page}
+ onChange={this.handlePageChange}
+ />
</div>
</div>
)}
);
}
- paginator() {
- return (
- <div class="mt-2">
- {this.state.page > 1 && (
- <button
- class="btn btn-secondary mr-1"
- onClick={linkEvent(this, this.prevPage)}
- >
- {i18n.t("prev")}
- </button>
- )}
- {this.unreadCount() > 0 && (
- <button
- class="btn btn-secondary"
- onClick={linkEvent(this, this.nextPage)}
- >
- {i18n.t("next")}
- </button>
- )}
- </div>
- );
- }
-
- nextPage(i: Inbox) {
- i.state.page++;
- i.setState(i.state);
- i.refetch();
- }
-
- prevPage(i: Inbox) {
- i.state.page--;
- i.setState(i.state);
- i.refetch();
+ handlePageChange(page: number) {
+ this.setState({ page });
+ this.refetch();
}
handleUnreadOrAllChange(i: Inbox, event: any) {
import { i18n } from "../i18next";
import { T } from "inferno-i18next";
import { HtmlTags } from "./html-tags";
+import { Paginator } from "./paginator";
interface MainState {
subscribedCommunities: CommunityFollowerView[];
this.handleSortChange = this.handleSortChange.bind(this);
this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
+ this.handlePageChange = this.handlePageChange.bind(this);
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
}
this.state.trendingCommunities = this.isoData.routeData[1].communities;
if (UserService.Instance.localUserView) {
- this.state.subscribedCommunities = this.isoData.routeData[2].communities;
+ this.state.subscribedCommunities =
+ this.isoData.routeData[2].communities;
}
this.state.loading = false;
} else {
<div>
{this.selects()}
{this.listings()}
- {this.paginator()}
+ <Paginator
+ page={this.state.page}
+ onChange={this.handlePageChange}
+ />
</div>
)}
</div>
);
}
- paginator() {
- return (
- <div class="my-2">
- {this.state.page > 1 && (
- <button
- class="btn btn-secondary mr-1"
- onClick={linkEvent(this, this.prevPage)}
- >
- {i18n.t("prev")}
- </button>
- )}
- {this.state.posts.length > 0 && (
- <button
- class="btn btn-secondary"
- onClick={linkEvent(this, this.nextPage)}
- >
- {i18n.t("next")}
- </button>
- )}
- </div>
- );
- }
-
get canAdmin(): boolean {
return (
UserService.Instance.localUserView &&
this.setState(this.state);
}
- nextPage(i: Main) {
- i.updateUrl({ page: i.state.page + 1 });
- window.scrollTo(0, 0);
- }
-
- prevPage(i: Main) {
- i.updateUrl({ page: i.state.page - 1 });
+ handlePageChange(page: number) {
+ this.updateUrl({ page });
window.scrollTo(0, 0);
}
-import { Component, linkEvent } from "inferno";
+import { Component } from "inferno";
import { Link } from "inferno-router";
import { Subscription } from "rxjs";
import {
import { PersonListing } from "./person-listing";
import { CommunityLink } from "./community-link";
import { Spinner } from "./icon";
+import { Paginator } from "./paginator";
enum ModlogEnum {
ModRemovePost,
super(props, context);
this.state = this.emptyState;
+ this.handlePageChange = this.handlePageChange.bind(this);
+
this.state.communityId = this.props.match.params.community_id
? Number(this.props.match.params.community_id)
: undefined;
combined.push(...banned);
if (this.state.communityId && combined.length > 0) {
- this.state.communityName = (combined[0]
- .view as ModRemovePostView).community.name;
+ this.state.communityName = (
+ combined[0].view as ModRemovePostView
+ ).community.name;
}
// Sort them by time
</thead>
{this.combined()}
</table>
- {this.paginator()}
+ <Paginator
+ page={this.state.page}
+ onChange={this.handlePageChange}
+ />
</div>
</div>
)}
);
}
- paginator() {
- return (
- <div class="mt-2">
- {this.state.page > 1 && (
- <button
- class="btn btn-secondary mr-1"
- onClick={linkEvent(this, this.prevPage)}
- >
- {i18n.t("prev")}
- </button>
- )}
- <button
- class="btn btn-secondary"
- onClick={linkEvent(this, this.nextPage)}
- >
- {i18n.t("next")}
- </button>
- </div>
- );
- }
-
- nextPage(i: Modlog) {
- i.state.page++;
- i.setState(i.state);
- i.refetch();
- }
-
- prevPage(i: Modlog) {
- i.state.page--;
- i.setState(i.state);
- i.refetch();
+ handlePageChange(val: number) {
+ this.setState({ page: val });
+ this.refetch();
}
refetch() {
--- /dev/null
+import { Component, linkEvent } from "inferno";
+import { i18n } from "../i18next";
+
+interface PaginatorProps {
+ page: number;
+ onChange(val: number): any;
+}
+
+export class Paginator extends Component<PaginatorProps, any> {
+ constructor(props: any, context: any) {
+ super(props, context);
+ }
+ render() {
+ return (
+ <div class="my-2">
+ <button
+ class="btn btn-secondary mr-2"
+ disabled={this.props.page == 1}
+ onClick={linkEvent(this, this.handlePrev)}
+ >
+ {i18n.t("prev")}
+ </button>
+ <button
+ class="btn btn-secondary"
+ onClick={linkEvent(this, this.handleNext)}
+ >
+ {i18n.t("next")}
+ </button>
+ </div>
+ );
+ }
+
+ handlePrev(i: Paginator) {
+ i.props.onChange(i.props.page - 1);
+ }
+
+ handleNext(i: Paginator) {
+ i.props.onChange(i.props.page + 1);
+ }
+}
-import { Component, linkEvent } from "inferno";
-import { i18n } from "../i18next";
+import { Component } from "inferno";
import {
PostView,
CommentView,
import { commentsToFlatNodes, setupTippy } from "../utils";
import { PostListing } from "./post-listing";
import { CommentNodes } from "./comment-nodes";
+import { Paginator } from "./paginator";
interface PersonDetailsProps {
personRes: GetPersonDetailsResponse;
export class PersonDetails extends Component<PersonDetailsProps, any> {
constructor(props: any, context: any) {
super(props, context);
+ this.handlePageChange = this.handlePageChange.bind(this);
}
// TODO needed here?
return (
<div>
{this.viewSelector(this.props.view)}
- {this.paginator()}
+
+ <Paginator page={this.props.page} onChange={this.handlePageChange} />
</div>
);
}
);
}
- paginator() {
- return (
- <div class="my-2">
- {this.props.page > 1 && (
- <button
- class="btn btn-secondary mr-1"
- onClick={linkEvent(this, this.prevPage)}
- >
- {i18n.t("prev")}
- </button>
- )}
- {this.props.personRes.comments.length +
- this.props.personRes.posts.length >
- 0 && (
- <button
- class="btn btn-secondary"
- onClick={linkEvent(this, this.nextPage)}
- >
- {i18n.t("next")}
- </button>
- )}
- </div>
- );
- }
-
- nextPage(i: PersonDetails) {
- i.props.onPageChange(i.props.page + 1);
- }
-
- prevPage(i: PersonDetails) {
- i.props.onPageChange(i.props.page - 1);
+ handlePageChange(val: number) {
+ this.props.onPageChange(val);
}
}
import { SortSelect } from "./sort-select";
import { ListingTypeSelect } from "./listing-type-select";
import { CommentNodes } from "./comment-nodes";
+import { Paginator } from "./paginator";
import { i18n } from "../i18next";
import { InitialFetchRequest } from "shared/interfaces";
this.state = this.emptyState;
this.handleSortChange = this.handleSortChange.bind(this);
this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
+ this.handlePageChange = this.handlePageChange.bind(this);
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
{this.state.type_ == SearchType.Users && this.users()}
{this.state.type_ == SearchType.Url && this.posts()}
{this.resultsCount() == 0 && <span>{i18n.t("no_results")}</span>}
- {this.paginator()}
+ <Paginator page={this.state.page} onChange={this.handlePageChange} />
</div>
);
}
);
}
- paginator() {
- return (
- <div class="mt-2">
- {this.state.page > 1 && (
- <button
- class="btn btn-secondary mr-1"
- onClick={linkEvent(this, this.prevPage)}
- >
- {i18n.t("prev")}
- </button>
- )}
-
- {this.resultsCount() > 0 && (
- <button
- class="btn btn-secondary"
- onClick={linkEvent(this, this.nextPage)}
- >
- {i18n.t("next")}
- </button>
- )}
- </div>
- );
- }
-
resultsCount(): number {
let res = this.state.searchResponse;
return (
);
}
- nextPage(i: Search) {
- i.updateUrl({ page: i.state.page + 1 });
- }
-
- prevPage(i: Search) {
- i.updateUrl({ page: i.state.page - 1 });
+ handlePageChange(page: number) {
+ this.updateUrl({ page });
}
search() {