import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { shareApi } from "../api/endpoints"; import type { ShareInfo } from "../api/types"; import { errorMessage, Loading, Modal } from "./ui"; /** Share a report or an infographic by link: turn the link on or off, copy it, and choose whether the page shows its sources. */ export function ShareDialog({ artifactId, onClose, what = "report" }: { artifactId: string; onClose: () => void; what?: "report" | "infographic" }) { const [info, setInfo] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [copied, setCopied] = useState(false); useEffect(() => { shareApi.get(artifactId).then(setInfo).catch((e) => setError(errorMessage(e))); }, [artifactId]); const run = async (act: () => Promise) => { setBusy(true); setError(null); try { setInfo(await act()); } catch (e) { setError(errorMessage(e)); } finally { setBusy(false); } }; const copy = async () => { if (!info?.url) return; try { await navigator.clipboard.writeText(info.url); setCopied(true); setTimeout(() => setCopied(false), 1800); } catch { setError("Could not copy. Select the link and copy it by hand."); } }; return (
{!info && !error && } {info && !info.shared && ( <>

Make a link anyone can open to see this {what}. They don't need an account, and they can't edit or see your posts, only the {what}.

)} {info?.shared && info.url && ( <>
e.currentTarget.select()} />
{what === "report" && ( )} The page shows the {what} only: no source text, no quotes and no name. Stopping ends the link for good, and sharing again makes a new one.
Open the page
)} {error && (

{error} Settings

)}
); }