"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import type { FeedItem } from "../../lib/fixtures"; import { PLATFORMS, type Platform } from "../../lib/platforms"; import type { ConnectionSummary } from "../../lib/api-types"; import { useApiResource } from "../../lib/use-api"; import { Sheet } from "./sheet"; import { nativeAmplifyActions } from "../../lib/amplify"; const identity = (value: ConnectionSummary[]): ConnectionSummary[] => value; const empty: ConnectionSummary[] = []; export function AmplifySheet({ post, platform, open, onClose }: { post: FeedItem | null; platform: Platform | null; open: boolean; onClose: () => void }): React.ReactElement { const router = useRouter(); const connections = useApiResource("/connections", identity, empty); const [picked, setPicked] = useState([]); const [notice, setNotice] = useState(""); const native = platform === null ? [] : nativeAmplifyActions(platform); function compose(ids: string[]): void { if (post === null) return; const params = new URLSearchParams({ text: `${post.text}\n\nVia ${post.handle}`, targets: ids.join(",") }); onClose(); router.push(`/compose?${params.toString()}`); } async function share(): Promise { if (post === null) return; const url = window.location.href; if (navigator.share) await navigator.share({ title: `Post by ${post.handle}`, text: post.text, url }).catch(() => undefined); else if (navigator.clipboard) { await navigator.clipboard.writeText(`${post.text}\n${url}`); setNotice("Post text copied"); } } return }> {platform !== null && <>

Native on {platform.displayName}

{native.length === 0 ?

This platform exposes no native amplify action.

: native.map((action) => )} } {notice &&

{notice}

}

Crosspost to your other accounts

{connections.source !== "live" &&

Connect to the API to choose publishing accounts.

} {connections.data.filter((connection) => connection.provider !== platform?.id).map((connection) => { const target = PLATFORMS[connection.provider]; const reason = !target?.capabilities.publishText ? "Text publishing unavailable" : target.capabilities.requiresMediaForPublish && !post?.hasMedia ? `${target.displayName} needs media` : connection.health !== "healthy" ? "Reconnect account first" : ""; return ; })}
; }