Skip to content

Commit

Permalink
Merge pull request #2852 from GreenAsJade/vote_post_error_handling
Browse files Browse the repository at this point in the history
Tell CMs if their vote errors on the back end
  • Loading branch information
anoek authored Oct 17, 2024
2 parents d55e08e + a448994 commit 02d3016
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
35 changes: 22 additions & 13 deletions src/lib/report_manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,22 +351,31 @@ class ReportManager extends EventEmitter<Events> {
this.updateIncidentReport(res);
return res;
}

public vote(report_id: number, voted_action: string, escalation_note: string): Promise<Report> {
const res = post(`moderation/incident/${report_id}`, {
action: "vote", // darn, yes, two different uses of the word "action" collide here
return post(`moderation/incident/${report_id}`, {
action: "vote",
voted_action: voted_action,
escalation_note: escalation_note,
}).then((res) => {
toast(
<div>
{pgettext("Thanking a community moderator for voting", "Submitted, thanks!")}
</div>,
2000,
);
this.updateIncidentReport(res);
return res;
});
return res;
})
.then((res) => {
toast(
<div>
{pgettext(
"Thanking a community moderator for voting",
"Submitted, thanks!",
)}
</div>,
2000,
);
this.updateIncidentReport(res);
return res;
})
.catch((error) => {
void alert.fire(`Error during vote submission: ${error.error}`);
console.error("Error during vote submission:", error);
throw error;
});
}

public getHandledTodayCount(): number {
Expand Down
3 changes: 1 addition & 2 deletions src/views/ReportsCenter/ViewReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export function ViewReport({ report_id, reports, onChange }: ViewReportProps): J
</div>
)}

{((!user.is_moderator && user.moderator_powers) || null) && (
{!user.is_moderator && user.moderator_powers && (
<div className="voting">
<ModerationActionSelector
available_actions={availableActions ?? []}
Expand All @@ -568,7 +568,6 @@ export function ViewReport({ report_id, reports, onChange }: ViewReportProps): J
(!report.escalated ||
!!(user.moderator_powers & MODERATOR_POWERS.SUSPEND))
}
// clear the selection for subsequent reports
key={report.id}
report={report}
/>
Expand Down

0 comments on commit 02d3016

Please sign in to comment.