Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.4 kB · 70 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import { useCallback, useEffect, useState } from "react";import { place } from "streamplace";import { useDID } from "../streamplace-store/streamplace-store";import { usePDSAgent, usePossiblyUnauthedPDSAgent,} from "../streamplace-store/xrpc";
export type BetaStatus = "granted" | "requested" | "none";
// Reports the logged-in account's access status for a named beta feature// (e.g. "vod") via place.stream.beta.getStatus. The DID is passed explicitly// so the query works against the unauthenticated node agent. Returns// status=null while loading or when logged out.export function useBetaStatus(feature: string) { const agent = usePossiblyUnauthedPDSAgent(); const did = useDID(); const [status, setStatus] = useState<BetaStatus | null>(null); const [loading, setLoading] = useState(true); const [error, setError] = useState<string | null>(null);
const refetch = useCallback(async () => { if (!agent || !did) { setStatus(null); setLoading(false); return; } setLoading(true); setError(null); try { const res = await agent.client.call(place.stream.beta.getStatus, { feature, did: did as any, }); setStatus(res.status as BetaStatus); } catch (e: any) { console.error("error fetching beta status", e); setError(e?.message ?? "failed to load beta status"); } finally { setLoading(false); } }, [agent, did, feature]);
useEffect(() => { refetch(); }, [refetch]);
// Optimistically reflect a just-published request without waiting for the // firehose to index it and getStatus to catch up. const markRequested = useCallback(() => setStatus("requested"), []);
return { status, loading, error, refetch, markRequested, did };}
// Publishes a place.stream.beta.request record in the caller's own repo,// asking for access to the named feature. The requesting account is the// record's authority, so no subject field is needed.export function useRequestBetaAccess(feature: string) { const agent = usePDSAgent(); const did = useDID(); return useCallback(async () => { if (!agent || !did) { throw new Error("not logged in"); } return await agent.client.create(place.stream.beta.request, { feature, createdAt: new Date().toISOString() as any, }); }, [agent, did, feature]);}