johnandersen777.bsky.social/knotless
git that lives in your Atmosphere account
Forked from chadtmiller.com/knotless
0
0
<script lang="ts">
import type * as createReport from '#lib/lexicons/dev/knotless/createReport.ts';
import { call } from '#lib/data.ts';
import { REPORT, reporting } from '#lib/report.svelte.ts';
import Dialog from '#lib/molecules/Dialog.svelte';
/**
* Reporting what `reporting` names to the moderation service, as whoever
* is logged in: why, from atproto's reasons, and more in words.
*/
const reasons = [
['spam', 'Spam'],
['violation', 'Breaks the rules or the law'],
['misleading', 'Misleading'],
['sexual', 'Sexual content'],
['rude', 'Rude or harassing'],
['other', 'Something else']
];
let reason = $state('spam');
let text = $state('');
let problem = $state('');
let sent = $state(false);
let busy = $state(false);
async function submit(e: SubmitEvent) {
e.preventDefault();
busy = true;
problem = '';
const input = { subject: reporting.subject, reason, text: text || undefined };
const done = await call<typeof createReport.main>('dev.knotless.createReport', input).then(
() => '',
(e: Error) => e.message
);
problem = done;
sent = !done;
if (sent) text = '';
busy = false;
}
function toggled(e: ToggleEvent) {
if (e.newState === 'open') {
sent = false;
problem = '';
}
}
</script>
<Dialog id={REPORT} title={`Report ${reporting.what || 'this'}`} ontoggle={toggled}>
{#if sent}
<p class="sent">Sent to the moderators. Thank you.</p>
{:else}
<form onsubmit={submit}>
<label for="report-reason">Why</label>
<select id="report-reason" name="reason" bind:value={reason}>
{#each reasons as [value, said] (value)}<option {value}>{said}</option>{/each}
</select>
<label for="report-text">More, for the moderators</label>
<textarea id="report-text" name="text" rows="4" bind:value={text}></textarea>
{#if problem}<p class="problem" role="alert">{problem}</p>{/if}
<button
class="btn primary"
type="submit"
disabled={busy || !reporting.subject}
aria-busy={busy}>{busy ? 'Sending…' : 'Send report'}</button
>
</form>
{/if}
</Dialog>