diff --git a/lemmy-translations b/lemmy-translations index 22637606..302cf963 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 22637606f4a4455458e64cefe9f5ec33dccb6c52 +Subproject commit 302cf9633459ba9a0998a98551b0c178f804c6d8 diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 4c5bce22..f4d141b6 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -68,6 +68,7 @@ import { CommunityLink } from "../community/community-link"; import { PersonListing } from "../person/person-listing"; import { CommentForm } from "./comment-form"; import { CommentNodes } from "./comment-nodes"; +import ReportForm from "../common/report-form"; interface CommentNodeState { showReply: boolean; @@ -90,7 +91,6 @@ interface CommentNodeState { viewSource: boolean; showAdvanced: boolean; showReportDialog: boolean; - reportReason?: string; createOrEditCommentLoading: boolean; upvoteLoading: boolean; downvoteLoading: boolean; @@ -105,7 +105,6 @@ interface CommentNodeState { addAdminLoading: boolean; transferCommunityLoading: boolean; fetchChildrenLoading: boolean; - reportLoading: boolean; purgeLoading: boolean; } @@ -179,7 +178,6 @@ export class CommentNode extends Component { addAdminLoading: false, transferCommunityLoading: false, fetchChildrenLoading: false, - reportLoading: false, purgeLoading: false, }; @@ -232,7 +230,6 @@ export class CommentNode extends Component { addAdminLoading: false, transferCommunityLoading: false, fetchChildrenLoading: false, - reportLoading: false, purgeLoading: false, }); } @@ -978,33 +975,10 @@ export class CommentNode extends Component { )} {this.state.showReportDialog && ( -
- - - -
+ )} {this.state.showBanDialog && (
@@ -1279,10 +1253,6 @@ export class CommentNode extends Component { i.setState({ showReportDialog: !i.state.showReportDialog }); } - handleReportReasonChange(i: CommentNode, event: any) { - i.setState({ reportReason: event.target.value }); - } - handleModRemoveShow(i: CommentNode) { i.setState({ showRemoveDialog: !i.state.showRemoveDialog, @@ -1538,21 +1508,17 @@ export class CommentNode extends Component { }); } - handleReportComment(i: CommentNode, event: any) { - event.preventDefault(); - i.setState({ reportLoading: true }); - i.props.onCommentReport({ - comment_id: i.commentId, - reason: i.state.reportReason ?? "", + handleReportComment = (reason: string) => { + this.props.onCommentReport({ + comment_id: this.commentId, + reason, auth: myAuthRequired(), }); - i.setState({ - reportLoading: false, - reportReason: undefined, + this.setState({ showReportDialog: false, }); - } + }; handlePurgeBothSubmit(i: CommentNode, event: any) { event.preventDefault(); diff --git a/src/shared/components/common/report-form.tsx b/src/shared/components/common/report-form.tsx new file mode 100644 index 00000000..c26e7736 --- /dev/null +++ b/src/shared/components/common/report-form.tsx @@ -0,0 +1,69 @@ +import { Component, linkEvent } from "inferno"; +import { I18NextService } from "../../services/I18NextService"; +import { Spinner } from "./icon"; + +interface ReportFormProps { + onSubmit: (reason: string) => void; + id: string; +} + +interface ReportFormState { + loading: boolean; + reason: string; +} + +function handleReportReasonChange(i: ReportForm, event: any) { + i.setState({ reason: event.target.value }); +} + +function handleReportSubmit(i: ReportForm, event: any) { + event.preventDefault(); + i.setState({ loading: true }); + i.props.onSubmit(i.state.reason); + + i.setState({ + loading: false, + reason: "", + }); +} + +export default class ReportForm extends Component< + ReportFormProps, + ReportFormState +> { + state: ReportFormState = { + loading: false, + reason: "", + }; + constructor(props, context) { + super(props, context); + } + + render() { + const { id } = this.props; + const { loading, reason } = this.state; + + return ( + + + + + + ); + } +} diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 67d70c43..d2bb0878 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -62,6 +62,7 @@ import { CommunityLink } from "../community/community-link"; import { PersonListing } from "../person/person-listing"; import { MetadataCard } from "./metadata-card"; import { PostForm } from "./post-form"; +import ReportForm from "../common/report-form"; interface PostListingState { showEdit: boolean; @@ -84,8 +85,6 @@ interface PostListingState { showMoreMobile: boolean; showBody: boolean; showReportDialog: boolean; - reportReason?: string; - reportLoading: boolean; blockLoading: boolean; lockLoading: boolean; deleteLoading: boolean; @@ -152,7 +151,6 @@ export class PostListing extends Component { showBody: false, showReportDialog: false, purgeLoading: false, - reportLoading: false, blockLoading: false, lockLoading: false, deleteLoading: false, @@ -182,7 +180,6 @@ export class PostListing extends Component { if (this.props !== nextProps) { this.setState({ purgeLoading: false, - reportLoading: false, blockLoading: false, lockLoading: false, deleteLoading: false, @@ -1288,30 +1285,10 @@ export class PostListing extends Component { )} {this.state.showReportDialog && ( -
- - - -
+ )} {this.state.showPurgeDialog && (
{ i.setState({ showReportDialog: !i.state.showReportDialog }); } - handleReportReasonChange(i: PostListing, event: any) { - i.setState({ reportReason: event.target.value }); - } - - handleReportSubmit(i: PostListing, event: any) { - event.preventDefault(); - i.setState({ reportLoading: true }); - i.props.onPostReport({ - post_id: i.postView.post.id, - reason: i.state.reportReason ?? "", + handleReportSubmit = (reason: string) => { + this.props.onPostReport({ + post_id: this.postView.post.id, + reason, auth: myAuthRequired(), }); - i.setState({ - reportLoading: false, + this.setState({ showReportDialog: false, - reportReason: undefined, }); - } + }; handleBlockPersonClick(i: PostListing) { i.setState({ blockLoading: true }); diff --git a/src/shared/components/private_message/private-message.tsx b/src/shared/components/private_message/private-message.tsx index 73c3c86c..d0b9556f 100644 --- a/src/shared/components/private_message/private-message.tsx +++ b/src/shared/components/private_message/private-message.tsx @@ -15,6 +15,7 @@ import { Icon, Spinner } from "../common/icon"; import { MomentTime } from "../common/moment-time"; import { PersonListing } from "../person/person-listing"; import { PrivateMessageForm } from "./private-message-form"; +import ReportForm from "../common/report-form"; interface PrivateMessageState { showReply: boolean; @@ -22,10 +23,8 @@ interface PrivateMessageState { collapsed: boolean; viewSource: boolean; showReportDialog: boolean; - reportReason?: string; deleteLoading: boolean; readLoading: boolean; - reportLoading: boolean; } interface PrivateMessageProps { @@ -49,7 +48,6 @@ export class PrivateMessage extends Component< showReportDialog: false, deleteLoading: false, readLoading: false, - reportLoading: false, }; constructor(props: any, context: any) { @@ -76,7 +74,6 @@ export class PrivateMessage extends Component< showReportDialog: false, deleteLoading: false, readLoading: false, - reportLoading: false, }); } } @@ -251,34 +248,10 @@ export class PrivateMessage extends Component< )} {this.state.showReportDialog && ( - - - - -
+ )} {this.state.showReply && (
@@ -362,23 +335,15 @@ export class PrivateMessage extends Component< i.setState({ showReportDialog: !i.state.showReportDialog }); } - handleReportReasonChange(i: PrivateMessage, event: any) { - i.setState({ reportReason: event.target.value }); - } - - handleReportSubmit(i: PrivateMessage, event: any) { - event.preventDefault(); - i.setState({ reportLoading: true }); - i.props.onReport({ - private_message_id: i.props.private_message_view.private_message.id, - reason: i.state.reportReason ?? "", + handleReportSubmit = (reason: string) => { + this.props.onReport({ + private_message_id: this.props.private_message_view.private_message.id, + reason, auth: myAuthRequired(), }); - i.setState({ - reportLoading: false, + this.setState({ showReportDialog: false, - reportReason: undefined, }); - } + }; }