/* * Based on frontpage/atproto-browser * Copyright (c) 2025 The Frontpage Authors * MIT License */ import React, { useState, useEffect } from 'react' import { parseAtUri, getRecord } from '../lib/atproto.js' import AtUriJson from './AtUriJson.jsx' export default function AtUriViewer({ uri, onAtUriClick }) { const [record, setRecord] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { const loadRecord = async () => { if (!uri) return setLoading(true) setError(null) try { const atUri = parseAtUri(uri) if (!atUri) { throw new Error('Invalid AT URI') } const result = await getRecord(atUri.hostname, atUri.collection, atUri.rkey) if (!result.success) { throw new Error(result.error) } setRecord(result.data) } catch (err) { setError(err.message) } finally { setLoading(false) } } loadRecord() }, [uri]) if (loading) { return (