diff --git a/src/components/Composer.tsx b/src/components/Composer.tsx index 2dd7f0c..4d852b0 100644 --- a/src/components/Composer.tsx +++ b/src/components/Composer.tsx @@ -1,4 +1,4 @@ -import { RichText } from "@atproto/api"; +import { AppBskyRichtextFacet, RichText } from "@atproto/api"; import { useAtom } from "jotai"; import { Dialog } from "radix-ui"; import { useEffect, useRef, useState } from "react"; @@ -48,6 +48,21 @@ export function Composer() { const rt = new RichText({ text: postText }); await rt.detectFacets(agent); + if (rt.facets?.length) { + rt.facets = rt.facets.filter((item) => { + if (item.$type !== "app.bsky.richtext.facet") return true; + if (!item.features?.length) return true; + + item.features = item.features.filter((feature) => { + if (feature.$type !== "app.bsky.richtext.facet#mention") return true; + const did = feature.$type === "app.bsky.richtext.facet#mention" ? (feature as AppBskyRichtextFacet.Mention)?.did : undefined; + return typeof did === "string" && did.startsWith("did:"); + }); + + return item.features.length > 0; + }); + } + const record: Record = { $type: "app.bsky.feed.post", text: rt.text, diff --git a/src/components/UniversalPostRenderer.tsx b/src/components/UniversalPostRenderer.tsx index 6e1b2cc..e705570 100644 --- a/src/components/UniversalPostRenderer.tsx +++ b/src/components/UniversalPostRenderer.tsx @@ -2649,7 +2649,7 @@ function extractFacetRanges(text: string, facets: Facet[]): FacetRange[] { return { start, end, feature: f.features[0] }; }); } -function renderTextWithFacets({ +export function renderTextWithFacets({ text, facets, navigate, diff --git a/src/routes/profile.$did/index.tsx b/src/routes/profile.$did/index.tsx index 916aae4..1e0d24e 100644 --- a/src/routes/profile.$did/index.tsx +++ b/src/routes/profile.$did/index.tsx @@ -1,10 +1,11 @@ +import { RichText } from "@atproto/api"; import { useQueryClient } from "@tanstack/react-query"; -import { createFileRoute } from "@tanstack/react-router"; +import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { useAtom } from "jotai"; -import React from "react"; +import React, { type ReactNode,useEffect, useState } from "react"; import { Header } from "~/components/Header"; -import { UniversalPostRendererATURILoader } from "~/components/UniversalPostRenderer"; +import { renderTextWithFacets, UniversalPostRendererATURILoader } from "~/components/UniversalPostRenderer"; import { useAuth } from "~/providers/UnifiedAuthProvider"; import { imgCDNAtom } from "~/utils/atoms"; import { toggleFollow, useGetFollowState, useGetOneToOneState } from "~/utils/followState"; @@ -21,6 +22,7 @@ export const Route = createFileRoute("/profile/$did/")({ function ProfileComponent() { // booo bad this is not always the did it might be a handle, use identity.did instead const { did } = Route.useParams(); + const navigate = useNavigate(); const queryClient = useQueryClient(); const { data: identity, @@ -175,7 +177,8 @@ function ProfileComponent() { {description && (
- {description} + {/* {description} */} +
)} @@ -308,4 +311,45 @@ export function Mutual({targetdidorhandle}:{targetdidorhandle: string}) { )} ); +} + +export function RichTextRenderer({ description }: { description: string }) { + const [richDescription, setRichDescription] = useState(description); + const { agent } = useAuth(); + const navigate = useNavigate(); + + useEffect(() => { + let mounted = true; + + // setRichDescription(description); + + async function processRichText() { + try { + if (!agent?.did) return; + const rt = new RichText({ text: description }); + await rt.detectFacets(agent); + + if (!mounted) return; + + if (rt.facets) { + setRichDescription(renderTextWithFacets({ text: rt.text, facets: rt.facets, navigate })); + } else { + setRichDescription(rt.text); + } + } catch (error) { + console.error("Failed to detect facets:", error); + if (mounted) { + setRichDescription(description); + } + } + } + + processRichText(); + + return () => { + mounted = false; + }; + }, [description, agent, navigate]); + + return <>{richDescription}; } \ No newline at end of file