Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246<script lang="ts"> import Globe from "$icon/globe"; import Pencil from "$icon/pencil"; import Trash2 from "$icon/trash-2"; import { didOf, type KnotOrigin } from "#lib/api/syntax.ts"; import type { Blob } from "@atcute/lexicons/interfaces"; import { uploadPending, type PendingImage } from "#lib/api/markupBlobs.ts"; import { createBobbinClient } from "#lib/api/client.ts"; import { didFromUri } from "#lib/api/uri.ts"; import type { CommentView } from "#lib/components/comment/comments.ts"; import type { ReactionGroup } from "#lib/components/reaction/reactions.ts"; import { createOptimisticReactions } from "#lib/components/reaction/reactions.svelte.ts"; import ReactionPicker from "#lib/components/reaction/ReactionPicker.svelte"; import Reactions from "#lib/components/reaction/Reactions.svelte"; import Tag from "#lib/components/ui/Tag.svelte"; import TimeAgo from "#lib/components/ui/TimeAgo.svelte"; import User from "#lib/components/ui/User.svelte"; import MoreMenu from "#lib/components/ui/MoreMenu.svelte"; import DropdownItem from "#lib/components/ui/DropdownItem.svelte"; import Separator from "#lib/components/ui/Separator.svelte"; import ConfirmModal from "#lib/components/ui/ConfirmModal.svelte"; import ReportItems from "#lib/components/moderation/ReportItems.svelte"; import { createReporting } from "#lib/components/moderation/reporting.svelte.ts"; import type { MarkupContext } from "#lib/markup/index.ts"; import Markup from "#lib/components/ui/Markup.svelte"; import PullReviewCommentEditor from "#lib/components/repo/pulls/PullReviewCommentEditor.svelte"; import ProfilePopover from "#lib/components/profile/ProfilePopover.svelte"; import VouchAvatar from "#lib/components/profile/VouchAvatar.svelte"; import { getAuth } from "#lib/auth.svelte.ts";
interface Props { comment: CommentView; active?: boolean; reactions?: ReactionGroup[]; knot?: KnotOrigin; markup: MarkupContext; onedit: (edited: CommentView, blobs: Blob[]) => Promise<void>; ondelete: (comment: CommentView) => Promise<void>; onreactionschange?: (next: ReactionGroup[]) => void; }
let editing = $state(false); let deleting = $state(false); let deleteOpen = $state(false);
let { comment, active = false, reactions, knot, markup, onedit, ondelete, onreactionschange }: Props = $props();
const auth = getAuth(); const currentUser = $derived(auth?.currentUser ?? null); const reporting = createReporting(); // the comment lives in the repo's account, so its images do too const owner = $derived(didOf(didFromUri(comment.uri)));
const held = createOptimisticReactions({ loaded: (uri) => (uri === comment.uri ? (reactions ?? comment.reactions ?? []) : undefined), viewer: () => currentUser }); const groups = $derived(held.of(comment.uri));
const setGroups = (next: ReactionGroup[]) => { held.set(comment.uri, next); onreactionschange?.(next); };
async function submit(body: string, pending: PendingImage[]) { const blobs = pending.length && auth?.agent ? await uploadPending( auth.agent, createBobbinClient({ serviceUrl: auth.bobbinUrl }), owner, pending, body ) : []; await onedit({ ...comment, body, reactions: groups }, blobs); editing = false; }
const confirmDelete = async () => { deleting = true; try { await ondelete(comment); deleteOpen = false; } finally { deleting = false; } }; // markup colours its headings, links, quotes and code itself, so an outdated // round has to flatten every descendant onto the one dimmed colour const outdatedMarkup = "text-foreground-subtle [&_*]:!text-inherit";</script>
<div class="group grid grid-cols-[auto_minmax(0,1fr)] gap-x-1.5 p-xs defer-render-28 {active ? 'text-foreground-default' : 'text-foreground-subtle'}"> <div class="row-span-2 self-start"> <ProfilePopover identifier={comment.authorDid}> <VouchAvatar did={comment.authorDid} handle={comment.authorHandle} size="large" /> </ProfilePopover> </div> <div class="flex min-w-0 flex-wrap items-center gap-x-xs gap-y-2xs"> <!-- User pins its own `text-foreground-default`, so the dimmed state has to say so --> <ProfilePopover identifier={comment.authorDid}> <User did={comment.authorDid} handle={comment.authorHandle} link showImage={false} handleClass="font-semibold" class={active ? undefined : "text-foreground-subtle"} /> </ProfilePopover> {#if comment.embed} <span class="inline-flex shrink-0 items-center gap-2xs"> <span class="text-foreground-subtle" aria-hidden="true">@</span> <Tag class="py-2xs typography-monospace-small font-normal {active ? '' : 'text-foreground-subtle'}" >{comment.embed.change?.slice(0, 8) ?? comment.embed.commit.slice(0, 8)}</Tag > </span> {/if} <a id="comment-{comment.rkey}" href="#comment-{comment.rkey}" class="shrink-0 no-underline hover:underline {active ? 'text-foreground-muted' : 'text-foreground-subtle'}" > {#if comment.editedAt && !comment.deleted} Edited <TimeAgo value={comment.editedAt} /> {:else} <TimeAgo value={comment.createdAt} /> {/if} </a> {#if !comment.deleted} <div class="ml-auto flex shrink-0 items-center gap-3xs text-foreground-muted opacity-0 transition group-hover:opacity-100 focus-within:opacity-100" > {#if currentUser} <ReactionPicker subjectUri={comment.uri} subjectCid={comment.cid} {knot} {groups} onchange={setGroups} dropdownOrigin="tr" dropdownAlign="right" triggerClass="hit-area-x-0.5 overflow-visible" /> {/if} <MoreMenu group="comment-actions" size="small" width="fit" triggerClass="hit-area-x-0.5 overflow-visible" label={`More actions for ${comment.authorHandle}'s comment`} > {#if auth?.hasAccount(comment.authorDid)} <DropdownItem icon={Pencil} onclick={() => (editing = true)} >Edit comment</DropdownItem > <DropdownItem icon={Trash2} danger={true} disabled={deleting} onclick={() => (deleteOpen = true)} > Delete comment </DropdownItem> <Separator /> {/if} <DropdownItem icon={Globe} onclick={() => navigator.clipboard.writeText(comment.uri)} > Copy AT URI </DropdownItem> {#if reporting.canReport(comment.authorDid)} <Separator /> {/if} <ReportItems subjectUri={comment.uri} subjectCid={comment.cid} subjectNoun="comment" authorDid={comment.authorDid} authorHandle={comment.authorHandle} /> </MoreMenu> </div> {/if} </div> <div class="col-start-2"> {#if editing} <PullReviewCommentEditor body={comment.body} {markup} {owner} submitLabel="Save" onsubmit={submit} oncancel={() => (editing = false)} /> {:else} <Markup source={comment.body} ctx={markup} tag="article" data-testid="reviewCommentBody" data-rkey={comment.rkey} class="markup mt-2xs {active ? '' : outdatedMarkup}" plainClass="mt-2xs wrap-anywhere whitespace-pre-wrap" /> {/if} <Reactions reactions={groups} subjectUri={comment.uri} subjectCid={comment.cid} {knot} onchange={setGroups} class="mt-2xs" /> </div></div>
<ConfirmModal bind:open={deleteOpen} title="Delete comment?" description="This cannot be undone." confirmLabel="Delete" loading={deleting} onconfirm={confirmDelete}/>