"use client"; import { ButtonPrimary } from "components/Buttons"; import { useActionState, useEffect, useState } from "react"; import { Input } from "components/Input"; import { useIdentityData } from "components/IdentityProvider"; import { confirmEmailAuthToken, requestAuthEmailToken, } from "actions/emailAuth"; import { subscribeToPublicationWithEmail } from "actions/subscribeToPublicationWithEmail"; import { ArrowRightTiny } from "components/Icons/ArrowRightTiny"; import { ShareSmall } from "components/Icons/ShareSmall"; import { Popover } from "components/Popover"; import { BlueskyTiny } from "components/Icons/BlueskyTiny"; import { useToaster } from "components/Toast"; import * as Dialog from "@radix-ui/react-dialog"; import { subscribeToPublication, unsubscribeToPublication, } from "./subscribeToPublication"; import { DotLoader } from "components/utils/DotLoader"; import { addFeed } from "./addFeed"; import { useSearchParams } from "next/navigation"; import LoginForm from "app/login/LoginForm"; import { RSSSmall } from "components/Icons/RSSSmall"; import { OAuthErrorMessage, isOAuthSessionError } from "components/OAuthError"; import { RSSTiny } from "components/Icons/RSSTiny"; export const SubscribeWithBluesky = (props: { compact?: boolean; pubName: string; pub_uri: string; base_url: string; subscribers: { identity: string }[]; }) => { let { identity } = useIdentityData(); let searchParams = useSearchParams(); let [successModalOpen, setSuccessModalOpen] = useState( !!searchParams.has("showSubscribeSuccess"), ); let [localSubscribeState, setLocalSubscribeState] = useState< "subscribed" | "unsubscribed" >("subscribed"); let subscribed = identity?.atp_did && localSubscribeState !== "unsubscribed" && props.subscribers.find((s) => s.identity === identity.atp_did); if (successModalOpen) return ( ); if (subscribed) { return ( setLocalSubscribeState("unsubscribed")} /> ); } return (
setLocalSubscribeState("subscribed")} compact={props.compact} pub_uri={props.pub_uri} setSuccessModalOpen={setSuccessModalOpen} /> {props.compact ? ( ) : ( )}
); }; export const ManageSubscription = (props: { pub_uri: string; subscribers: { identity: string }[]; base_url: string; compact?: boolean; onUnsubscribe?: () => void; }) => { let toaster = useToaster(); let [hasFeed] = useState(false); let [, unsubscribe, unsubscribePending] = useActionState(async () => { await unsubscribeToPublication(props.pub_uri); toaster({ content: "You unsubscribed.", type: "success", }); props.onUnsubscribe?.(); }, null); return ( Manage Subscription } >

Update Options

{!hasFeed && ( Bluesky Custom Feed )} Get RSS
); }; let BlueskySubscribeButton = (props: { pub_uri: string; setSuccessModalOpen: (open: boolean) => void; compact?: boolean; setLocalSubscribeState: () => void; }) => { let { identity } = useIdentityData(); let toaster = useToaster(); let [oauthError, setOauthError] = useState< import("src/atproto-oauth").OAuthSessionError | null >(null); let [, subscribe, subscribePending] = useActionState(async () => { setOauthError(null); let result = await subscribeToPublication( props.pub_uri, window.location.href + "?refreshAuth", ); if (!result.success) { if (isOAuthSessionError(result.error)) { setOauthError(result.error); } return; } if (result.hasFeed === false) { props.setSuccessModalOpen(true); } toaster({ content:
You're Subscribed!
, type: "success" }); props.setLocalSubscribeState(); }, null); let [isClient, setIsClient] = useState(false); useEffect(() => { setIsClient(true); }, []); if (!identity?.atp_did) { return ( Subscribe with Bluesky } > {isClient && ( )} ); } return (
{subscribePending ? ( ) : ( <> Subscribe with Bluesky )}
{oauthError && ( )}
); }; const SubscribeSuccessModal = ({ open, setOpen, }: { open: boolean; setOpen: (open: boolean) => void; }) => { let searchParams = useSearchParams(); let [loading, setLoading] = useState(false); let toaster = useToaster(); return (

Subscribed!

You'll get updates about this publication via a Feed just for you. { if (loading) return; setLoading(true); let feedurl = "https://bsky.app/profile/leaflet.pub/feed/subscribedPublications"; await addFeed(); toaster({ content: "Feed added!", type: "success" }); setLoading(false); window.open(feedurl, "_blank"); }} > {loading ? : "Add Bluesky Feed"}
); }; export const SubscribeOnPost = () => { return
; };