import React, { useState, useEffect } from 'react' import { useAuth } from './hooks/useAuth.js' import { useAdminData } from './hooks/useAdminData.js' import { useUserData } from './hooks/useUserData.js' import { usePageContext } from './hooks/usePageContext.js' import AuthButton from './components/AuthButton.jsx' import RecordTabs from './components/RecordTabs.jsx' import CommentForm from './components/CommentForm.jsx' import AskAI from './components/AskAI.jsx' import TestUI from './components/TestUI.jsx' import OAuthCallback from './components/OAuthCallback.jsx' export default function App() { const { user, agent, loading: authLoading, login, logout } = useAuth() const { adminData, langRecords, commentRecords, loading: dataLoading, error, retryCount, refresh: refreshAdminData } = useAdminData() const { userComments, chatRecords, loading: userLoading, refresh: refreshUserData } = useUserData(adminData) const pageContext = usePageContext() const [showAskAI, setShowAskAI] = useState(false) const [showTestUI, setShowTestUI] = useState(false) // Event listeners for blog communication useEffect(() => { const handleAIQuestion = (event) => { const { question } = event.detail if (question && adminData && user && agent) { // Automatically open Ask AI panel and submit question setShowAskAI(true) // We'll need to pass this to the AskAI component // For now, let's just open the panel } } const dispatchAIProfileLoaded = () => { if (adminData?.profile) { window.dispatchEvent(new CustomEvent('aiProfileLoaded', { detail: { did: adminData.did, handle: adminData.profile.handle, displayName: adminData.profile.displayName, avatar: adminData.profile.avatar } })) } } // Listen for questions from blog window.addEventListener('postAIQuestion', handleAIQuestion) // Dispatch AI profile when adminData is available if (adminData?.profile) { dispatchAIProfileLoaded() } return () => { window.removeEventListener('postAIQuestion', handleAIQuestion) } }, [adminData, user, agent]) // Handle OAuth callback if (window.location.search.includes('code=')) { return } const isLoading = authLoading || dataLoading || userLoading if (isLoading) { return (

ATProto OAuth Demo

読み込み中...

) } if (error) { return (

ATProto OAuth Demo

エラー: {error}

{retryCount > 0 && (

自動リトライ中... ({retryCount}/3)

)}
) } return (
{ refreshAdminData?.() refreshUserData?.() }} />
{ refreshAdminData?.() refreshUserData?.() }} /> {showTestUI && (
)}
) }