import { useState } from "npm:preact/hooks"; const u = (url = "", params = {}) => { let result = new URL(url, window.location.href); Object.entries(params).forEach((kv) => { let [k, v] = kv; result.searchParams.set(k, v as string); }); return result.toString(); }; export interface MastodonShareButtonProps { title: string; url: string; series?: string; tags: string; } export default function MastodonShareButton( { title, url, series, tags }: MastodonShareButtonProps, ) { let defaultURL = localStorage["mastodon_instance"]; if (defaultURL == undefined) { defaultURL = ""; } const tootTemplate = `${title} ${url} ${series ? "#" + series + " " : ""}${ tags ? tags.map((x) => "#" + x).join(" ") : "" } @cadey@pony.social`; const [getURL, setURL] = useState(defaultURL); const [getToot, setToot] = useState(tootTemplate); return (
Share on Mastodon {"Instance URL (https://mastodon.example)"}
setURL(e.target.value)} />

); }