2021-09-28 10:38:59 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import {
|
|
|
|
CommentReportResponse,
|
|
|
|
CommentReportView,
|
2022-06-21 21:42:29 +00:00
|
|
|
GetSiteResponse,
|
2021-09-28 10:38:59 +00:00
|
|
|
ListCommentReports,
|
|
|
|
ListCommentReportsResponse,
|
|
|
|
ListPostReports,
|
|
|
|
ListPostReportsResponse,
|
2022-09-28 12:50:47 +00:00
|
|
|
ListPrivateMessageReports,
|
|
|
|
ListPrivateMessageReportsResponse,
|
2021-09-28 10:38:59 +00:00
|
|
|
PostReportResponse,
|
|
|
|
PostReportView,
|
2022-09-28 12:50:47 +00:00
|
|
|
PrivateMessageReportResponse,
|
|
|
|
PrivateMessageReportView,
|
2023-06-14 12:20:40 +00:00
|
|
|
ResolveCommentReport,
|
|
|
|
ResolvePostReport,
|
|
|
|
ResolvePrivateMessageReport,
|
2021-09-28 10:38:59 +00:00
|
|
|
} from "lemmy-js-client";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { InitialFetchRequest } from "../../interfaces";
|
2023-06-14 12:20:40 +00:00
|
|
|
import { HttpService, UserService } from "../../services";
|
|
|
|
import { FirstLoadService } from "../../services/FirstLoadService";
|
|
|
|
import { RequestState } from "../../services/HttpService";
|
2021-09-28 10:38:59 +00:00
|
|
|
import {
|
2023-06-16 02:08:14 +00:00
|
|
|
RouteDataResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
editCommentReport,
|
|
|
|
editPostReport,
|
|
|
|
editPrivateMessageReport,
|
2021-09-28 10:38:59 +00:00
|
|
|
fetchLimit,
|
2023-06-14 12:20:40 +00:00
|
|
|
myAuthRequired,
|
2021-09-28 10:38:59 +00:00
|
|
|
setIsoData,
|
|
|
|
} from "../../utils";
|
2023-06-16 21:07:55 +00:00
|
|
|
import { amAdmin } from "../../utils/roles/am-admin";
|
2021-12-30 15:26:45 +00:00
|
|
|
import { CommentReport } from "../comment/comment-report";
|
2021-09-28 10:38:59 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Spinner } from "../common/icon";
|
|
|
|
import { Paginator } from "../common/paginator";
|
2021-12-30 15:26:45 +00:00
|
|
|
import { PostReport } from "../post/post-report";
|
2022-09-28 12:50:47 +00:00
|
|
|
import { PrivateMessageReport } from "../private_message/private-message-report";
|
2021-09-28 10:38:59 +00:00
|
|
|
|
|
|
|
enum UnreadOrAll {
|
|
|
|
Unread,
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageType {
|
|
|
|
All,
|
|
|
|
CommentReport,
|
|
|
|
PostReport,
|
2022-09-28 12:50:47 +00:00
|
|
|
PrivateMessageReport,
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageEnum {
|
|
|
|
CommentReport,
|
|
|
|
PostReport,
|
2022-09-28 12:50:47 +00:00
|
|
|
PrivateMessageReport,
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
type ReportsData = RouteDataResponse<{
|
2023-06-16 02:39:04 +00:00
|
|
|
commentReportsRes: ListCommentReportsResponse;
|
|
|
|
postReportsRes: ListPostReportsResponse;
|
|
|
|
messageReportsRes: ListPrivateMessageReportsResponse;
|
2023-06-16 02:08:14 +00:00
|
|
|
}>;
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2021-09-28 10:38:59 +00:00
|
|
|
type ItemType = {
|
|
|
|
id: number;
|
|
|
|
type_: MessageEnum;
|
2022-09-28 12:50:47 +00:00
|
|
|
view: CommentReportView | PostReportView | PrivateMessageReportView;
|
2021-09-28 10:38:59 +00:00
|
|
|
published: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
interface ReportsState {
|
2023-06-14 12:20:40 +00:00
|
|
|
commentReportsRes: RequestState<ListCommentReportsResponse>;
|
|
|
|
postReportsRes: RequestState<ListPostReportsResponse>;
|
|
|
|
messageReportsRes: RequestState<ListPrivateMessageReportsResponse>;
|
2021-09-28 10:38:59 +00:00
|
|
|
unreadOrAll: UnreadOrAll;
|
|
|
|
messageType: MessageType;
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2023-05-15 19:53:29 +00:00
|
|
|
page: number;
|
2023-06-14 12:20:40 +00:00
|
|
|
isIsomorphic: boolean;
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Reports extends Component<any, ReportsState> {
|
2023-05-30 00:40:00 +00:00
|
|
|
private isoData = setIsoData<ReportsData>(this.context);
|
2023-01-04 16:56:24 +00:00
|
|
|
state: ReportsState = {
|
2023-06-14 12:20:40 +00:00
|
|
|
commentReportsRes: { state: "empty" },
|
|
|
|
postReportsRes: { state: "empty" },
|
|
|
|
messageReportsRes: { state: "empty" },
|
2021-09-28 10:38:59 +00:00
|
|
|
unreadOrAll: UnreadOrAll.Unread,
|
|
|
|
messageType: MessageType.All,
|
2023-05-15 19:53:29 +00:00
|
|
|
page: 1,
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2023-06-14 12:20:40 +00:00
|
|
|
isIsomorphic: false,
|
2021-09-28 10:38:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
2023-06-14 12:20:40 +00:00
|
|
|
this.handleResolveCommentReport =
|
|
|
|
this.handleResolveCommentReport.bind(this);
|
|
|
|
this.handleResolvePostReport = this.handleResolvePostReport.bind(this);
|
|
|
|
this.handleResolvePrivateMessageReport =
|
|
|
|
this.handleResolvePrivateMessageReport.bind(this);
|
2021-09-28 10:38:59 +00:00
|
|
|
|
|
|
|
// Only fetch the data if coming from another route
|
2023-06-14 12:20:40 +00:00
|
|
|
if (FirstLoadService.isFirstLoad) {
|
2023-06-16 02:39:04 +00:00
|
|
|
const { commentReportsRes, postReportsRes, messageReportsRes } =
|
2023-06-14 12:20:40 +00:00
|
|
|
this.isoData.routeData;
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-06-14 12:20:40 +00:00
|
|
|
commentReportsRes,
|
|
|
|
postReportsRes,
|
|
|
|
isIsomorphic: true,
|
2022-09-22 15:03:35 +00:00
|
|
|
};
|
2023-06-14 12:20:40 +00:00
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
if (amAdmin()) {
|
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-06-16 02:39:04 +00:00
|
|
|
messageReportsRes: messageReportsRes,
|
2022-09-28 12:50:47 +00:00
|
|
|
};
|
|
|
|
}
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async componentDidMount() {
|
|
|
|
if (!this.state.isIsomorphic) {
|
|
|
|
await this.refetch();
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2023-06-05 21:31:12 +00:00
|
|
|
const mui = UserService.Instance.myUserInfo;
|
2023-01-04 16:56:24 +00:00
|
|
|
return mui
|
|
|
|
? `@${mui.local_user_view.person.name} ${i18n.t("reports")} - ${
|
2022-11-09 19:53:07 +00:00
|
|
|
this.state.siteRes.site_view.site.name
|
2023-01-04 16:56:24 +00:00
|
|
|
}`
|
|
|
|
: "";
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2023-06-14 12:20:40 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
|
|
|
<h5 className="mb-2">{i18n.t("reports")}</h5>
|
|
|
|
{this.selects()}
|
|
|
|
{this.section}
|
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
2021-09-28 10:38:59 +00:00
|
|
|
</div>
|
2023-06-14 12:20:40 +00:00
|
|
|
</div>
|
2021-09-28 10:38:59 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
get section() {
|
|
|
|
switch (this.state.messageType) {
|
|
|
|
case MessageType.All: {
|
|
|
|
return this.all();
|
|
|
|
}
|
|
|
|
case MessageType.CommentReport: {
|
|
|
|
return this.commentReports();
|
|
|
|
}
|
|
|
|
case MessageType.PostReport: {
|
|
|
|
return this.postReports();
|
|
|
|
}
|
|
|
|
case MessageType.PrivateMessageReport: {
|
|
|
|
return this.privateMessageReports();
|
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:59 +00:00
|
|
|
unreadOrAllRadios() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mb-2">
|
2021-09-28 10:38:59 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UnreadOrAll.Unread}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.Unread}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("unread")}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.unreadOrAll == UnreadOrAll.All && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={UnreadOrAll.All}
|
|
|
|
checked={this.state.unreadOrAll == UnreadOrAll.All}
|
|
|
|
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("all")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
messageTypeRadios() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="btn-group btn-group-toggle flex-wrap mb-2">
|
2021-09-28 10:38:59 +00:00
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.messageType == MessageType.All && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.All}
|
|
|
|
checked={this.state.messageType == MessageType.All}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("all")}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.messageType == MessageType.CommentReport && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.CommentReport}
|
|
|
|
checked={this.state.messageType == MessageType.CommentReport}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("comments")}
|
|
|
|
</label>
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${this.state.messageType == MessageType.PostReport && "active"}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.PostReport}
|
|
|
|
checked={this.state.messageType == MessageType.PostReport}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("posts")}
|
|
|
|
</label>
|
2022-09-28 12:50:47 +00:00
|
|
|
{amAdmin() && (
|
|
|
|
<label
|
|
|
|
className={`btn btn-outline-secondary pointer
|
|
|
|
${
|
|
|
|
this.state.messageType == MessageType.PrivateMessageReport &&
|
|
|
|
"active"
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
value={MessageType.PrivateMessageReport}
|
|
|
|
checked={
|
|
|
|
this.state.messageType == MessageType.PrivateMessageReport
|
|
|
|
}
|
|
|
|
onChange={linkEvent(this, this.handleMessageTypeChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t("messages")}
|
|
|
|
</label>
|
|
|
|
)}
|
2021-09-28 10:38:59 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-2">
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="mr-3">{this.unreadOrAllRadios()}</span>
|
|
|
|
<span className="mr-3">{this.messageTypeRadios()}</span>
|
2021-09-28 10:38:59 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
commentReportToItemType(r: CommentReportView): ItemType {
|
2021-09-28 10:38:59 +00:00
|
|
|
return {
|
|
|
|
id: r.comment_report.id,
|
|
|
|
type_: MessageEnum.CommentReport,
|
|
|
|
view: r,
|
|
|
|
published: r.comment_report.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
postReportToItemType(r: PostReportView): ItemType {
|
2021-09-28 10:38:59 +00:00
|
|
|
return {
|
|
|
|
id: r.post_report.id,
|
|
|
|
type_: MessageEnum.PostReport,
|
|
|
|
view: r,
|
|
|
|
published: r.post_report.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
privateMessageReportToItemType(r: PrivateMessageReportView): ItemType {
|
|
|
|
return {
|
|
|
|
id: r.private_message_report.id,
|
|
|
|
type_: MessageEnum.PrivateMessageReport,
|
|
|
|
view: r,
|
|
|
|
published: r.private_message_report.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
get buildCombined(): ItemType[] {
|
|
|
|
const commentRes = this.state.commentReportsRes;
|
2023-06-05 21:31:12 +00:00
|
|
|
const comments =
|
2023-06-14 12:20:40 +00:00
|
|
|
commentRes.state == "success"
|
|
|
|
? commentRes.data.comment_reports.map(this.commentReportToItemType)
|
|
|
|
: [];
|
|
|
|
|
|
|
|
const postRes = this.state.postReportsRes;
|
2023-06-05 21:31:12 +00:00
|
|
|
const posts =
|
2023-06-14 12:20:40 +00:00
|
|
|
postRes.state == "success"
|
|
|
|
? postRes.data.post_reports.map(this.postReportToItemType)
|
|
|
|
: [];
|
|
|
|
const pmRes = this.state.messageReportsRes;
|
2023-06-05 21:31:12 +00:00
|
|
|
const privateMessages =
|
2023-06-14 12:20:40 +00:00
|
|
|
pmRes.state == "success"
|
|
|
|
? pmRes.data.private_message_reports.map(
|
|
|
|
this.privateMessageReportToItemType
|
|
|
|
)
|
|
|
|
: [];
|
2022-09-28 12:50:47 +00:00
|
|
|
|
|
|
|
return [...comments, ...posts, ...privateMessages].sort((a, b) =>
|
2021-09-28 10:38:59 +00:00
|
|
|
b.published.localeCompare(a.published)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderItemType(i: ItemType) {
|
|
|
|
switch (i.type_) {
|
|
|
|
case MessageEnum.CommentReport:
|
|
|
|
return (
|
2023-06-14 12:20:40 +00:00
|
|
|
<CommentReport
|
|
|
|
key={i.id}
|
|
|
|
report={i.view as CommentReportView}
|
|
|
|
onResolveReport={this.handleResolveCommentReport}
|
|
|
|
/>
|
2021-09-28 10:38:59 +00:00
|
|
|
);
|
|
|
|
case MessageEnum.PostReport:
|
2023-06-14 12:20:40 +00:00
|
|
|
return (
|
|
|
|
<PostReport
|
|
|
|
key={i.id}
|
|
|
|
report={i.view as PostReportView}
|
|
|
|
onResolveReport={this.handleResolvePostReport}
|
|
|
|
/>
|
|
|
|
);
|
2022-09-28 12:50:47 +00:00
|
|
|
case MessageEnum.PrivateMessageReport:
|
|
|
|
return (
|
|
|
|
<PrivateMessageReport
|
|
|
|
key={i.id}
|
|
|
|
report={i.view as PrivateMessageReportView}
|
2023-06-14 12:20:40 +00:00
|
|
|
onResolveReport={this.handleResolvePrivateMessageReport}
|
2022-09-28 12:50:47 +00:00
|
|
|
/>
|
|
|
|
);
|
2021-09-28 10:38:59 +00:00
|
|
|
default:
|
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
all() {
|
|
|
|
return (
|
|
|
|
<div>
|
2023-06-14 12:20:40 +00:00
|
|
|
{this.buildCombined.map(i => (
|
2021-09-28 10:38:59 +00:00
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
{this.renderItemType(i)}
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
commentReports() {
|
2023-06-14 12:20:40 +00:00
|
|
|
const res = this.state.commentReportsRes;
|
|
|
|
switch (res.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success": {
|
|
|
|
const reports = res.data.comment_reports;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{reports.map(cr => (
|
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
<CommentReport
|
|
|
|
key={cr.comment_report.id}
|
|
|
|
report={cr}
|
|
|
|
onResolveReport={this.handleResolveCommentReport}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
postReports() {
|
2023-06-14 12:20:40 +00:00
|
|
|
const res = this.state.postReportsRes;
|
|
|
|
switch (res.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success": {
|
|
|
|
const reports = res.data.post_reports;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{reports.map(pr => (
|
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
<PostReport
|
|
|
|
key={pr.post_report.id}
|
|
|
|
report={pr}
|
|
|
|
onResolveReport={this.handleResolvePostReport}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:50:47 +00:00
|
|
|
privateMessageReports() {
|
2023-06-14 12:20:40 +00:00
|
|
|
const res = this.state.messageReportsRes;
|
|
|
|
switch (res.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success": {
|
|
|
|
const reports = res.data.private_message_reports;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{reports.map(pmr => (
|
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
<PrivateMessageReport
|
|
|
|
key={pmr.private_message_report.id}
|
|
|
|
report={pmr}
|
|
|
|
onResolveReport={this.handleResolvePrivateMessageReport}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-09-28 12:50:47 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePageChange(page: number) {
|
2021-09-28 10:38:59 +00:00
|
|
|
this.setState({ page });
|
2023-06-14 12:20:40 +00:00
|
|
|
await this.refetch();
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleUnreadOrAllChange(i: Reports, event: any) {
|
2023-05-15 19:53:29 +00:00
|
|
|
i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
|
2023-06-14 12:20:40 +00:00
|
|
|
await i.refetch();
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleMessageTypeChange(i: Reports, event: any) {
|
2023-05-15 19:53:29 +00:00
|
|
|
i.setState({ messageType: Number(event.target.value), page: 1 });
|
2023-06-14 12:20:40 +00:00
|
|
|
await i.refetch();
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
static async fetchInitialData({
|
2023-06-14 12:20:40 +00:00
|
|
|
auth,
|
|
|
|
client,
|
2023-06-16 02:08:14 +00:00
|
|
|
}: InitialFetchRequest): Promise<ReportsData> {
|
2023-06-05 21:31:12 +00:00
|
|
|
const unresolved_only = true;
|
|
|
|
const page = 1;
|
|
|
|
const limit = fetchLimit;
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
const commentReportsForm: ListCommentReports = {
|
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth: auth as string,
|
|
|
|
};
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
const postReportsForm: ListPostReports = {
|
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth: auth as string,
|
|
|
|
};
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
const data: ReportsData = {
|
2023-06-16 02:39:04 +00:00
|
|
|
commentReportsRes: await client.listCommentReports(commentReportsForm),
|
|
|
|
postReportsRes: await client.listPostReports(postReportsForm),
|
|
|
|
messageReportsRes: { state: "empty" },
|
2023-05-30 00:40:00 +00:00
|
|
|
};
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
if (amAdmin()) {
|
|
|
|
const privateMessageReportsForm: ListPrivateMessageReports = {
|
2023-01-04 16:56:24 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
2023-05-30 00:40:00 +00:00
|
|
|
auth: auth as string,
|
2023-01-04 16:56:24 +00:00
|
|
|
};
|
|
|
|
|
2023-06-16 02:39:04 +00:00
|
|
|
data.messageReportsRes = await client.listPrivateMessageReports(
|
|
|
|
privateMessageReportsForm
|
2023-06-14 12:20:40 +00:00
|
|
|
);
|
2022-09-28 12:50:47 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
return data;
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async refetch() {
|
2023-06-05 21:31:12 +00:00
|
|
|
const unresolved_only = this.state.unreadOrAll == UnreadOrAll.Unread;
|
|
|
|
const page = this.state.page;
|
|
|
|
const limit = fetchLimit;
|
2023-06-14 12:20:40 +00:00
|
|
|
const auth = myAuthRequired();
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
commentReportsRes: { state: "loading" },
|
|
|
|
postReportsRes: { state: "loading" },
|
|
|
|
messageReportsRes: { state: "loading" },
|
|
|
|
});
|
|
|
|
|
|
|
|
const form:
|
|
|
|
| ListCommentReports
|
|
|
|
| ListPostReports
|
|
|
|
| ListPrivateMessageReports = {
|
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
auth,
|
|
|
|
};
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
this.setState({
|
|
|
|
commentReportsRes: await HttpService.client.listCommentReports(form),
|
|
|
|
postReportsRes: await HttpService.client.listPostReports(form),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (amAdmin()) {
|
|
|
|
this.setState({
|
|
|
|
messageReportsRes: await HttpService.client.listPrivateMessageReports(
|
|
|
|
form
|
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleResolveCommentReport(form: ResolveCommentReport) {
|
|
|
|
const res = await HttpService.client.resolveCommentReport(form);
|
|
|
|
this.findAndUpdateCommentReport(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleResolvePostReport(form: ResolvePostReport) {
|
|
|
|
const res = await HttpService.client.resolvePostReport(form);
|
|
|
|
this.findAndUpdatePostReport(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleResolvePrivateMessageReport(form: ResolvePrivateMessageReport) {
|
|
|
|
const res = await HttpService.client.resolvePrivateMessageReport(form);
|
|
|
|
this.findAndUpdatePrivateMessageReport(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
findAndUpdateCommentReport(res: RequestState<CommentReportResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.commentReportsRes.state == "success" && res.state == "success") {
|
|
|
|
s.commentReportsRes.data.comment_reports = editCommentReport(
|
|
|
|
res.data.comment_report_view,
|
|
|
|
s.commentReportsRes.data.comment_reports
|
2023-01-04 16:56:24 +00:00
|
|
|
);
|
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
return s;
|
|
|
|
});
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
findAndUpdatePostReport(res: RequestState<PostReportResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.postReportsRes.state == "success" && res.state == "success") {
|
|
|
|
s.postReportsRes.data.post_reports = editPostReport(
|
|
|
|
res.data.post_report_view,
|
|
|
|
s.postReportsRes.data.post_reports
|
|
|
|
);
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
findAndUpdatePrivateMessageReport(
|
|
|
|
res: RequestState<PrivateMessageReportResponse>
|
|
|
|
) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.messageReportsRes.state == "success" && res.state == "success") {
|
|
|
|
s.messageReportsRes.data.private_message_reports =
|
|
|
|
editPrivateMessageReport(
|
|
|
|
res.data.private_message_report_view,
|
|
|
|
s.messageReportsRes.data.private_message_reports
|
|
|
|
);
|
2022-09-28 12:50:47 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
return s;
|
|
|
|
});
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
}
|