diff --git a/src/components/FoundLogContent.tsx b/src/components/FoundLogContent.tsx index 4bac3620..7395e714 100644 --- a/src/components/FoundLogContent.tsx +++ b/src/components/FoundLogContent.tsx @@ -1,6 +1,11 @@ import { useMemo } from 'react'; +import { Link } from 'react-router-dom'; import { ShieldCheck } from 'lucide-react'; +import { nip19 } from 'nostr-tools'; import { Badge } from '@/components/ui/badge'; +import { Skeleton } from '@/components/ui/skeleton'; +import { ChestIcon } from '@/components/icons/ChestIcon'; +import { useAddrEvent, type AddrCoords } from '@/hooks/useEvent'; import type { NostrEvent } from '@nostrify/nostrify'; function getTag(tags: string[][], name: string): string | undefined { @@ -11,29 +16,55 @@ function getAllTags(tags: string[][], name: string): string[] { return tags.filter(([n]) => n === name).map(([, v]) => v); } +/** Parse the `a` tag from a found log into addressable event coordinates. */ +function parseGeocacheAddr(tags: string[][]): AddrCoords | undefined { + const aTag = getTag(tags, 'a'); + if (!aTag) return undefined; + const parts = aTag.split(':'); + if (parts.length < 3) return undefined; + const [kindStr, pubkey, ...rest] = parts; + const kind = Number(kindStr); + if (!kind || !pubkey) return undefined; + return { kind, pubkey, identifier: rest.join(':') }; +} + /** Renders the content of a found log event (kind 7516). */ export function FoundLogContent({ event }: { event: NostrEvent }) { const text = event.content; const images = getAllTags(event.tags, 'image'); const hasVerification = !!getTag(event.tags, 'verification'); - // Extract geocache name from the `a` tag if available - const geocacheRef = useMemo(() => { - const aTag = getTag(event.tags, 'a'); - if (!aTag) return null; - const [, , dTag] = aTag.split(':'); - return dTag ?? null; - }, [event.tags]); + const geocacheAddr = useMemo(() => parseGeocacheAddr(event.tags), [event.tags]); + const { data: geocacheEvent, isLoading: geocacheLoading } = useAddrEvent(geocacheAddr); + + const geocacheName = geocacheEvent?.tags.find(([n]) => n === 'name')?.[1]; + + // Build naddr link for the geocache + const geocacheLink = useMemo(() => { + if (!geocacheAddr) return undefined; + return `/${nip19.naddrEncode({ kind: geocacheAddr.kind, pubkey: geocacheAddr.pubkey, identifier: geocacheAddr.identifier })}`; + }, [geocacheAddr]); return (