"use client"; import { useState } from "react"; import useSWR from "swr"; import { AtUri } from "@atproto/syntax"; import { getReplyTargets } from "actions/replies"; import { PubIcon } from "components/ActionBar/Publications"; import { Avatar } from "components/Avatar"; import { LoadingTiny } from "components/Icons/LoadingTiny"; import { MoreOptionsVerticalTiny } from "components/Icons/MoreOptionsVerticalTiny"; import { Menu, MenuItem } from "components/Menu"; import { ButtonPrimary, ButtonTertiary } from "components/Buttons"; import { ProfilePopover } from "components/ProfilePopover"; import type { ReplyTarget, ReplyTargetsFor } from "src/documentReplies"; export const replyTargetsKey = ({ document, draftSubject }: ReplyTargetsFor) => document ? ["reply_targets", document] : draftSubject ? ["reply_targets", null, draftSubject] : null; export function useReplyTargets(args: ReplyTargetsFor) { return useSWR(replyTargetsKey(args), () => getReplyTargets(args)).data; } export function ReplyingTo(props: { targets: ReplyTarget[]; newTab?: boolean; onWithdraw?: (target: ReplyTarget) => Promise; className?: string; }) { let [withdrawn, setWithdrawn] = useState([]); let targets = props.targets.filter((t) => !withdrawn.includes(t.uri)); if (targets.length === 0) return null; let onWithdraw = props.onWithdraw; return (
{targets.map((target) => (
In reply to {target.publication ? ( ) : ( target.authorAvatar && ( ) )} {target.title} {target.authorHandle && (
by
)}
{target.pending && ( Pending )} {onWithdraw && ( { let ok = await onWithdraw(target).catch(() => false); if (ok) setWithdrawn((w) => [...w, target.uri]); return ok; }} /> )}
))}
); } function ReplyTargetOptions(props: { title: string; onWithdraw: () => Promise; }) { let [open, setOpen] = useState(false); let [confirming, setConfirming] = useState(false); let [withdrawing, setWithdrawing] = useState(false); return ( { if (withdrawing) return; setOpen(o); setConfirming(false); }} trigger={ } > {confirming ? (
Are you sure?
This post will no longer be a reply to {props.title}.
setConfirming(false)} > Nevermind { setWithdrawing(true); let ok = await props.onWithdraw(); setWithdrawing(false); if (ok) setOpen(false); }} > {withdrawing ? ( ) : ( "Yes, withdraw" )}
) : ( { e.preventDefault(); setConfirming(true); }} > Withdraw reply )}
); }