import m, {MithrilComponent} from '@garage44/mithril' import {Button, Card, FieldCheckbox, FieldText} from '@garage44/mithril/components' import type {UserReport} from '@/types' import {bind, local} from '@/lib/reactive' import {loadReports, resolveReport} from '@/lib/reports' import {formatTimestamp} from '@/lib/utils' /** The reasons the app's Report offers, as the server names them. */ const REASONS: Record = { harassment: 'Harassment or bullying', hate_speech: 'Hate speech or a slur', other: 'Something else', sexual_content: 'Sexual content', spam: 'Spam or a scam', threat: 'Threat or self-harm', } /** * Reports about a person, filed from the app: Admin › People › Reports. * * A report about a *line in a community's topic* is not here: it goes to that * community's moderators, through the chat (`docs/mockups/web-navigation/`, * "Decided"). This is the server's own queue, which until this page had no * screen at all — the simulator stored them and nobody could read them * without shell access. */ export class Reports extends MithrilComponent { s = local({ all: false, loaded: false, /** What the operator is writing about each report, by id. */ notes: {} as Record, reports: [] as UserReport[], }) /** The checkbox's model: changing it reloads the list. */ showAll = (() => { const page = this return { get value() { return page.s.all }, set value(v: boolean) { page.s.all = v void page.load() }, } })() oninit() { void this.load() } async load() { const got = await loadReports(this.s.all) if (got) this.s.reports = got this.s.loaded = true m.redraw() } async resolve(r: UserReport) { const note = (this.s.notes[r.id] ?? '').trim() if (await resolveReport(r.id, note)) { delete this.s.notes[r.id] await this.load() } } view() { const s = this.s const open = s.reports.filter((r) => !r.resolved).length return (

{!s.loaded ? 'Loading…' : open === 0 ? 'No open reports' : `${open} open ${open === 1 ? 'report' : 'reports'}`}

{s.loaded && s.reports.length === 0 && (

Nobody has reported anyone. Reports about a line in a community go to that community's moderators instead.

)} {s.reports.map((r) => (
{r.subject_username} {REASONS[r.reason] ?? r.reason} {formatTimestamp(r.created_at)}

Reported by {r.reporter_username || 'an account that has since been deleted'}

{r.message &&
“{r.message}”
} {r.note &&

{r.note}

} {r.resolved ? (

Closed {r.resolved_at ? formatTimestamp(r.resolved_at) : ''} {r.resolution ? `: ${r.resolution}` : ''}

) : (
)}
))}
) } }