import React, { useState } from 'react' import AvatarImage from './AvatarImage.jsx' import { getValidAvatar, clearAvatarCache, getAvatarCacheStats } from '../utils/avatarFetcher.js' export default function AvatarTestPanel() { const [testHandle, setTestHandle] = useState('ai.syui.ai') const [testResult, setTestResult] = useState(null) const [loading, setLoading] = useState(false) const [cacheStats, setCacheStats] = useState(null) // ダミーレコードを作成(実際の投稿したレコード形式) const createTestRecord = (handle, brokenAvatar = false) => ({ value: { author: { did: null, // DIDはnullにして、handleから取得させる handle: handle, displayName: "Test User", avatar: brokenAvatar ? "https://broken.example.com/avatar.jpg" : null }, text: "テストコメント", createdAt: new Date().toISOString() } }) const testAvatarFetch = async (useBrokenAvatar = false) => { setLoading(true) setTestResult(null) try { const testRecord = createTestRecord(testHandle, useBrokenAvatar) const avatarUrl = await getValidAvatar(testRecord) setTestResult({ success: true, avatarUrl, handle: testHandle, brokenTest: useBrokenAvatar, timestamp: new Date().toISOString() }) } catch (error) { setTestResult({ success: false, error: error.message, handle: testHandle, brokenTest: useBrokenAvatar }) } finally { setLoading(false) } } const handleClearCache = () => { clearAvatarCache() setCacheStats(null) alert('Avatar cache cleared!') } const handleShowCacheStats = () => { const stats = getAvatarCacheStats() setCacheStats(stats) } return (

🖼️ Avatar Test Panel

Avatar取得システムのテスト。投稿済みのdummy recordを使用してavatar取得処理を確認できます。

setTestHandle(e.target.value)} placeholder="ai.syui.ai" disabled={loading} />
{testResult && (

Test Result:

{testResult.success ? (
✅ Avatar fetched successfully!

Handle: {testResult.handle}

Broken Test: {testResult.brokenTest ? 'Yes' : 'No'}

Avatar URL: {testResult.avatarUrl || 'None'}

Timestamp: {testResult.timestamp}

{testResult.avatarUrl && (

Preview:

Avatar preview
)}
) : (
❌ Test failed: {testResult.error}
)}
)} {cacheStats && (

Cache Statistics:

Entries: {cacheStats.size}

{cacheStats.entries.length > 0 && (

Cached Avatars:

{cacheStats.entries.map((entry, i) => (

Key: {entry.key}

Age: {Math.floor(entry.age / 1000)}s

Profile: {entry.profile?.displayName} (@{entry.profile?.handle})

{entry.avatar && ( Cached avatar )}
))}
)}
)}

Live Avatar Component Demo:

実際のAvatarImageコンポーネントの動作確認:

Normal avatar test
Broken avatar test (should fetch fresh)
) }