Something went wrong. Try again.
Monorepo for Tangled
Something went wrong. Try again.
2.0 kB · 76 lines
Svelte
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677<script lang="ts"> import TriangleAlert from "$icon/triangle-alert"; import MessageSquareWarning from "$icon/message-square-warning"; import UserX from "$icon/user-x"; import type { ReportSubject } from "$lib/api/moderation"; import DropdownItem from "$lib/components/ui/DropdownItem.svelte"; import { tick } from "svelte"; import ReportDialog from "$lib/components/moderation/ReportDialog.svelte"; import { createReporting } from "$lib/components/moderation/reporting.svelte";
type SubjectNoun = "comment" | "reply" | "issue" | "pull request";
interface Props { authorDid: string; authorHandle: string; subjectUri?: string; subjectCid?: string; subjectNoun?: SubjectNoun; labelerDid?: string; }
let { authorDid, authorHandle, subjectUri, subjectCid, subjectNoun = "comment", labelerDid }: Props = $props();
const reporting = createReporting(() => labelerDid); const record = $derived<ReportSubject | null>( subjectUri && subjectCid ? { kind: "record", uri: subjectUri, cid: subjectCid } : null );
let open = $state(false); let subject = $state<ReportSubject | null>(null); let subjectLabel = $state("");
const icon = $derived.by(() => { switch (subjectNoun) { case "issue": case "pull request": return TriangleAlert; case "comment": case "reply": return MessageSquareWarning; } });
const openWith = async (next: ReportSubject, label: string) => { subject = next; subjectLabel = label; await tick(); open = true; };</script>
{#if reporting.canReport(authorDid)} {#if record} <DropdownItem {icon} onclick={() => openWith(record, `this ${subjectNoun}`)} danger={true}> Report {subjectNoun} </DropdownItem> {/if} <DropdownItem icon={UserX} onclick={() => openWith({ kind: "account", did: authorDid }, `@${authorHandle}`)} danger={true} > Report user </DropdownItem>
{#if subject} <ReportDialog bind:open {subject} {subjectLabel} labelerDid={reporting.labelerDid} /> {/if}{/if}