import React, { useState } from 'react' // Helper function to get correct web URL based on avatar URL function getCorrectWebUrl(avatarUrl) { if (!avatarUrl) return 'https://bsky.app' // If avatar is from bsky.app (main Bluesky), use bsky.app if (avatarUrl.includes('cdn.bsky.app') || avatarUrl.includes('bsky.app')) { return 'https://bsky.app' } // If avatar is from syu.is, use web.syu.is if (avatarUrl.includes('bsky.syu.is') || avatarUrl.includes('syu.is')) { return 'https://syu.is' } // Default to bsky.app return 'https://bsky.app' } export default function ProfileRecordList({ profileRecords, apiConfig, user = null, agent = null, onRecordDeleted = null }) { const [expandedRecords, setExpandedRecords] = useState(new Set()) const toggleJsonView = (uri) => { const newExpanded = new Set(expandedRecords) if (newExpanded.has(uri)) { newExpanded.delete(uri) } else { newExpanded.add(uri) } setExpandedRecords(newExpanded) } if (!profileRecords || profileRecords.length === 0) { return (

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

) } const handleDelete = async (profile) => { if (!user || !agent || !profile.uri) return const confirmed = window.confirm('このプロフィールを削除しますか?') if (!confirmed) return try { const uriParts = profile.uri.split('/') await agent.api.com.atproto.repo.deleteRecord({ repo: uriParts[2], collection: uriParts[3], rkey: uriParts[4] }) if (onRecordDeleted) { onRecordDeleted() } } catch (error) { alert(`削除に失敗しました: ${error.message}`) } } const canDelete = (profile) => { if (!user || !agent || !profile.uri) return false // Check if the record is in the current user's repository const recordRepoDid = profile.uri.split('/')[2] return recordRepoDid === user.did } return (
{profileRecords.map((profile) => (
{profile.value.author?.avatar ? ( {`${profile.value.author.displayName ) : (
{(profile.value.author?.displayName || profile.value.author?.handle || '?').charAt(0).toUpperCase()}
)}
{profile.value.author?.displayName || profile.value.author?.handle} {profile.value.profileType === 'admin' && ( Admin )}
@{profile.value.author?.handle}
{canDelete(profile) && ( )}
{expandedRecords.has(profile.uri) && (
                {JSON.stringify(profile, null, 2)}
              
)}
{profile.value.text}
))}
) }