import { Check, Copy, X } from "lucide-react"; import { useEffect, useState } from "react"; import { createPortal } from "react-dom"; import { api, errorMessage } from "../api"; import { copyToClipboard } from "../clipboard"; import { Alert, LoadingSurface } from "./ui"; // AddServerLinkModal shows a ready-made owpg://addserver link for this // exact server (host+port only -- see the Go handler's doc comment for why // name/description/key/DC are deliberately never embedded in it) -- an // operator hands this out (a website button, a QR code, a message // elsewhere) and the desktop/Android client's "Add Server" form opens // pre-filled from it, fetching the rest straight from this server itself. export function AddServerLinkModal({ onClose }: { onClose: () => void }) { const [link, setLink] = useState(null); const [error, setError] = useState(""); const [copied, setCopied] = useState(false); useEffect(() => { let cancelled = false; api.addServerLink() .then((result) => { if (!cancelled) setLink(result.link); }) .catch((err) => { if (!cancelled) setError(errorMessage(err)); }); return () => { cancelled = true; }; }, []); async function copy() { if (!link) return; try { await copyToClipboard(link); setCopied(true); } catch (err) { setError(errorMessage(err)); } } return createPortal(
{"Server"}

{"Share server"}

{"Share this link (a button, a QR code, a message) so anyone with the OwpenGram client can add this server in one tap. It only carries the address and port -- the client fetches the name, description, and key directly from the server itself, so the link can never be tampered with to point someone at a fake identity for this address."}

{error && {error}} {!link && !error && } {link && (