mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Adding modlog paging.
This commit is contained in:
parent
c4be18008a
commit
04f64184f6
2 changed files with 42 additions and 9 deletions
|
@ -1806,9 +1806,9 @@ impl Perform for GetModlog {
|
|||
let mut added = Vec::new();
|
||||
|
||||
if self.community_id.is_none() {
|
||||
removed_communities = ModRemoveCommunityView::list(&conn, self.mod_user_id, self.limit, self.page).unwrap();
|
||||
banned = ModBanView::list(&conn, self.mod_user_id, self.limit, self.page).unwrap();
|
||||
added = ModAddView::list(&conn, self.mod_user_id, self.limit, self.page).unwrap();
|
||||
removed_communities = ModRemoveCommunityView::list(&conn, self.mod_user_id, self.page, self.limit).unwrap();
|
||||
banned = ModBanView::list(&conn, self.mod_user_id, self.page, self.limit).unwrap();
|
||||
added = ModAddView::list(&conn, self.mod_user_id, self.page, self.limit).unwrap();
|
||||
}
|
||||
|
||||
// Return the jwt
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Component } from 'inferno';
|
||||
import { Component, linkEvent } from 'inferno';
|
||||
import { Link } from 'inferno-router';
|
||||
import { Subscription } from "rxjs";
|
||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
||||
import { UserOperation, GetModlogForm, GetModlogResponse, ModRemovePost, ModLockPost, ModRemoveComment, ModRemoveCommunity, ModBanFromCommunity, ModBan, ModAddCommunity, ModAdd } from '../interfaces';
|
||||
import { WebSocketService } from '../services';
|
||||
import { msgOp, addTypeInfo } from '../utils';
|
||||
import { msgOp, addTypeInfo, fetchLimit } from '../utils';
|
||||
import { MomentTime } from './moment-time';
|
||||
import * as moment from 'moment';
|
||||
|
||||
|
@ -12,6 +12,7 @@ interface ModlogState {
|
|||
combined: Array<{type_: string, data: ModRemovePost | ModLockPost | ModRemoveCommunity}>,
|
||||
communityId?: number,
|
||||
communityName?: string,
|
||||
page: number;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
|
@ -19,6 +20,7 @@ export class Modlog extends Component<any, ModlogState> {
|
|||
private subscription: Subscription;
|
||||
private emptyState: ModlogState = {
|
||||
combined: [],
|
||||
page: 1,
|
||||
loading: true,
|
||||
}
|
||||
|
||||
|
@ -35,10 +37,7 @@ export class Modlog extends Component<any, ModlogState> {
|
|||
() => console.log('complete')
|
||||
);
|
||||
|
||||
let modlogForm: GetModlogForm = {
|
||||
community_id: this.state.communityId
|
||||
};
|
||||
WebSocketService.Instance.getModlog(modlogForm);
|
||||
this.refetch();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -52,6 +51,7 @@ export class Modlog extends Component<any, ModlogState> {
|
|||
let removed_communities = addTypeInfo(res.removed_communities, "removed_communities");
|
||||
let banned_from_community = addTypeInfo(res.banned_from_community, "banned_from_community");
|
||||
let added_to_community = addTypeInfo(res.added_to_community, "added_to_community");
|
||||
this.state.combined = [];
|
||||
|
||||
this.state.combined.push(...removed_posts);
|
||||
this.state.combined.push(...locked_posts);
|
||||
|
@ -153,6 +153,7 @@ export class Modlog extends Component<any, ModlogState> {
|
|||
</thead>
|
||||
{this.combined()}
|
||||
</table>
|
||||
{this.paginator()}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
@ -160,6 +161,38 @@ export class Modlog extends Component<any, ModlogState> {
|
|||
);
|
||||
}
|
||||
|
||||
paginator() {
|
||||
return (
|
||||
<div class="mt-2">
|
||||
{this.state.page > 1 &&
|
||||
<button class="btn btn-sm btn-secondary mr-1" onClick={linkEvent(this, this.prevPage)}>Prev</button>
|
||||
}
|
||||
<button class="btn btn-sm btn-secondary" onClick={linkEvent(this, this.nextPage)}>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();
|
||||
}
|
||||
|
||||
refetch(){
|
||||
let modlogForm: GetModlogForm = {
|
||||
community_id: this.state.communityId,
|
||||
page: this.state.page,
|
||||
limit: fetchLimit,
|
||||
};
|
||||
WebSocketService.Instance.getModlog(modlogForm);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
console.log(msg);
|
||||
let op: UserOperation = msgOp(msg);
|
||||
|
|
Loading…
Reference in a new issue