import { actions } from 'astro:actions'; import { reports } from './state.ts'; import { actionErrorPopup } from '@util/action.ts'; import type { Report, ReportStatus } from './types.ts'; export async function fetchReports(reporterUsername: string | null, reportedUsername: string | null) { const { data, error } = await actions.report.reports({ reporter: reporterUsername, reported: reportedUsername }); if (error) { actionErrorPopup(error); return; } reports.set(data.reports); } export async function addReport(report: Report) { const { data, error } = await actions.report.addReport({ reason: report.reason, body: report.body, createdAt: report.createdAt, reporter: report.reporter.id, reported: report.reported?.id ?? null }); if (error) { actionErrorPopup(error); return; } reports.update((old) => { old.push(Object.assign(report, { id: data.id, status: null })); return old; }); } export async function getReportStatus(report: Report) { const { data, error } = await actions.report.reportStatus({ reportId: report.id }); if (error) { actionErrorPopup(error); return; } return data.reportStatus; } export async function editReportStatus(report: Report, reportStatus: ReportStatus) { const { error } = await actions.report.editReportStatus({ reportId: report.id, status: reportStatus.status, notice: reportStatus.notice, statement: reportStatus.statement, strikeId: reportStatus.strikeId }); if (error) { actionErrorPopup(error); } } export async function getStrikeReasons() { const { data, error } = await actions.report.strikeReasons(); if (error) { actionErrorPopup(error); return; } return data.strikeReasons; }