import React, { useState, useEffect } from 'react' import { collections } from '../api/atproto.js' import AvatarImage from './AvatarImage.jsx' import LoadingSkeleton from './LoadingSkeleton.jsx' const ProfileRecordList = ({ apiConfig, user, agent, onRecordDeleted }) => { const [profiles, setProfiles] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { if (apiConfig?.admin && apiConfig?.collection) { fetchProfiles() } }, [apiConfig]) const fetchProfiles = async () => { try { setLoading(true) setError(null) const adminProfiles = await collections.getProfiles( apiConfig.pds, apiConfig.admin, apiConfig.collection ) // Sort profiles: admin type first, then user type const sortedProfiles = adminProfiles.sort((a, b) => { if (a.value.type === 'admin' && b.value.type !== 'admin') return -1 if (a.value.type !== 'admin' && b.value.type === 'admin') return 1 return 0 }) setProfiles(sortedProfiles) } catch (err) { console.error('Failed to fetch profiles:', err) setError('プロフィールの読み込みに失敗しました') } finally { setLoading(false) } } const handleDelete = async (uri) => { if (!user || !agent) return if (!confirm('このプロフィールを削除しますか?')) return try { const rkey = uri.split('/').pop() await agent.api.com.atproto.repo.deleteRecord({ repo: user.did, collection: `${apiConfig.collection}.profile`, rkey: rkey }) // Invalidate cache and refresh collections.invalidateCache(`${apiConfig.collection}.profile`) await fetchProfiles() if (onRecordDeleted) { onRecordDeleted() } } catch (err) { console.error('Failed to delete profile:', err) setError('プロフィールの削除に失敗しました') } } if (loading) { return } if (error) { return (

{error}

) } if (profiles.length === 0) { return (

プロフィールがありません

) } return (
{profiles.map((profile) => (
{profile.value.author.displayName || profile.value.author.handle} {profile.value.type === 'admin' && ( Admin )}
@{profile.value.author.handle}
{new Date(profile.value.createdAt).toLocaleString()}
{user && (
)}
{profile.value.text}
))}
) } export default ProfileRecordList