forked from mirrors/pronouns.cc
frontend: add reports list
This commit is contained in:
parent
244c13cd84
commit
29274287a2
4 changed files with 56 additions and 4 deletions
|
@ -12,7 +12,9 @@ import (
|
||||||
type Report struct {
|
type Report struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
UserID xid.ID `json:"user_id"`
|
UserID xid.ID `json:"user_id"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
MemberID *xid.ID `json:"member_id"`
|
MemberID *xid.ID `json:"member_id"`
|
||||||
|
MemberName *string `json:"member_name"`
|
||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
ReporterID xid.ID `json:"reporter_id"`
|
ReporterID xid.ID `json:"reporter_id"`
|
||||||
|
|
||||||
|
@ -25,7 +27,12 @@ type Report struct {
|
||||||
const ReportPageSize = 100
|
const ReportPageSize = 100
|
||||||
|
|
||||||
func (db *DB) Reports(ctx context.Context, closed bool, before int) (rs []Report, err error) {
|
func (db *DB) Reports(ctx context.Context, closed bool, before int) (rs []Report, err error) {
|
||||||
builder := sq.Select("*").From("reports").Limit(ReportPageSize).OrderBy("id DESC")
|
builder := sq.Select("*",
|
||||||
|
"(SELECT username FROM users WHERE id = reports.user_id) AS user_name",
|
||||||
|
"(SELECT name FROM members WHERE id = reports.member_id) AS member_name").
|
||||||
|
From("reports").
|
||||||
|
Limit(ReportPageSize).
|
||||||
|
OrderBy("id DESC")
|
||||||
if before != 0 {
|
if before != 0 {
|
||||||
builder = builder.Where("id < ?", before)
|
builder = builder.Where("id < ?", before)
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,9 @@ export interface Invite {
|
||||||
export interface Report {
|
export interface Report {
|
||||||
id: string;
|
id: string;
|
||||||
user_id: string;
|
user_id: string;
|
||||||
|
user_name: string;
|
||||||
member_id: string | null;
|
member_id: string | null;
|
||||||
|
member_name: string | null;
|
||||||
reason: string;
|
reason: string;
|
||||||
reporter_id: string;
|
reporter_id: string;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,40 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { DateTime } from "luxon";
|
||||||
|
import { Button, Card, CardBody, CardFooter, CardHeader } from "sveltestrap";
|
||||||
import type { PageData } from "./$types";
|
import type { PageData } from "./$types";
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Reports - pronouns.cc</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>Reports</h1>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#each data.reports as report}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<strong>#{report.id}</strong> on <a href="/@{report.user_name}">@{report.user_name}</a>
|
||||||
|
({report.user_id}) {#if report.member_id}
|
||||||
|
(member: <a href="/@{report.user_name}/{report.member_name}">{report.member_name}</a>,
|
||||||
|
{report.member_id})
|
||||||
|
{/if}
|
||||||
|
</CardHeader>
|
||||||
|
<CardBody>
|
||||||
|
<blockquote class="blockquote">{report.reason}</blockquote>
|
||||||
|
</CardBody>
|
||||||
|
<CardFooter>
|
||||||
|
Created {DateTime.fromISO(report.created_at)
|
||||||
|
.toLocal()
|
||||||
|
.toLocaleString(DateTime.DATETIME_MED)} •
|
||||||
|
<Button outline color="warning" size="sm">Warn user</Button>
|
||||||
|
<Button outline color="danger" size="sm">Deactivate user</Button>
|
||||||
|
<Button outline color="secondary" size="sm">Ignore report</Button>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
import type { Report } from "$lib/api/entities";
|
import { ErrorCode, type APIError, type Report } from "$lib/api/entities";
|
||||||
import { apiFetchClient } from "$lib/api/fetch";
|
import { apiFetchClient } from "$lib/api/fetch";
|
||||||
|
import { error } from "@sveltejs/kit";
|
||||||
|
|
||||||
export const load = async () => {
|
export const load = async () => {
|
||||||
const reports = await apiFetchClient<Report[]>("/admin/reports");
|
try {
|
||||||
return { page: 0, isClosed: false, userId: null, reporterId: null, reports } as PageLoadData;
|
const reports = await apiFetchClient<Report[]>("/admin/reports");
|
||||||
|
return { page: 0, isClosed: false, userId: null, reporterId: null, reports } as PageLoadData;
|
||||||
|
} catch (e) {
|
||||||
|
if ((e as APIError).code === ErrorCode.Forbidden) {
|
||||||
|
throw error(400, "You're not an admin");
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PageLoadData {
|
interface PageLoadData {
|
||||||
|
|
Loading…
Reference in a new issue