import { u } from "@xeserv/xeact"; import { useState } from 'preact/hooks'; export interface MastodonShareButtonProps { title: string; url: string; series?: string; tags: string[]; } export default function MastodonShareButton( { title, url = u("", {}), 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 [theURL, setURL] = useState(defaultURL); const [toot, setToot] = useState(tootTemplate); return (
Share on Mastodon {"Instance URL (https://mastodon.example)"}
{ const target = e.target as HTMLInputElement; setURL(target.value); }} />

); }