import React, { useState } from 'react'; import { Pet, AnalysisResult, PetTimelineItem, DictionarySignal, TalkBackLog } from './types'; import { INITIAL_PET_LUNA, INITIAL_PET_MILO, INITIAL_TIMELINE_LUNA, INITIAL_DICTIONARY_LUNA } from './data/seedData'; import { Navigation } from './components/Navigation'; import { LandingPage } from './components/LandingPage'; import { OnboardingFlow } from './components/OnboardingFlow'; import { LiveListenScreen } from './components/LiveListenScreen'; import { TalkBackScreen } from './components/TalkBackScreen'; import { PetTimeline } from './components/PetTimeline'; import { InsightsScreen } from './components/InsightsScreen'; import { AuthPage } from './components/AuthPage'; import { useAuth } from './context/AuthContext'; export default function App() { const { user, isLoading, logout } = useAuth(); const [pets, setPets] = useState([INITIAL_PET_LUNA, INITIAL_PET_MILO]); const [selectedPetId, setSelectedPetId] = useState(INITIAL_PET_LUNA.id); const [currentView, setCurrentView] = useState<'landing' | 'onboarding' | 'listen' | 'talkback' | 'timeline' | 'insights'>('landing'); const [timelineItems, setTimelineItems] = useState(INITIAL_TIMELINE_LUNA); const [dictionarySignals, setDictionarySignals] = useState(INITIAL_DICTIONARY_LUNA); const selectedPet = pets.find(p => p.id === selectedPetId) || pets[0]; // Show loading spinner while checking auth if (isLoading) { return (
); } // Show auth page if not authenticated if (!user) { return ; } // Callback when analysis completes from LiveListenScreen const handleAnalysisComplete = (result: AnalysisResult) => { const newTimelineItem: PetTimelineItem = { id: `tl_${Date.now()}`, petId: result.petId, type: 'interpretation', title: result.primaryIntent.title, description: result.reasoning.summary, timestamp: result.timestamp, intentCategory: result.primaryIntent.category, confidence: result.primaryIntent.confidence, feedbackStatus: 'pending', zoneName: result.zoneName }; setTimelineItems(prev => [newTimelineItem, ...prev]); }; // Callback when pet model updates from training const handleUpdatePet = (updatedPet: Pet) => { setPets(prev => prev.map(p => p.id === updatedPet.id ? updatedPet : p)); }; // Callback when Talk Back reaction is logged const handleLogTalkBackReaction = (log: TalkBackLog) => { const newTimelineItem: PetTimelineItem = { id: `tl_tb_${Date.now()}`, petId: log.petId, type: 'talk_back', title: `Played "${log.messageLabel}" Tone`, description: `Pet reaction observed: ${log.petReaction ? log.petReaction.replace('_', ' ') : 'played'}`, timestamp: log.timestamp }; setTimelineItems(prev => [newTimelineItem, ...prev]); }; // Callback when manual event is added const handleAddManualEvent = (event: PetTimelineItem) => { setTimelineItems(prev => [event, ...prev]); }; // Callback when onboarding completes const handleCompleteOnboarding = (newPet: Pet) => { setPets(prev => [...prev, newPet]); setSelectedPetId(newPet.id); setCurrentView('listen'); }; // Callback to reset pet ML model const handleResetPetModel = () => { setPets(prev => prev.map(p => { if (p.id === selectedPetId) { return { ...p, confirmedSampleCount: 0, overallAccuracy: 75 }; } return p; })); alert(`${selectedPet.name}'s profile memory has been reset.`); }; // Callback to delete pet account const handleDeletePetAccount = () => { const remainingPets = pets.filter(p => p.id !== selectedPetId); if (remainingPets.length > 0) { setPets(remainingPets); setSelectedPetId(remainingPets[0].id); setCurrentView('landing'); } else { // Re-seed Luna if all pets deleted setPets([INITIAL_PET_LUNA]); setSelectedPetId(INITIAL_PET_LUNA.id); setCurrentView('landing'); } }; return (
{/* Global Responsive Navigation Header & Bottom Bar */} setCurrentView('onboarding')} /> {/* Main Content View Switcher */}
{currentView === 'landing' && ( setCurrentView('listen')} onStartOnboarding={() => setCurrentView('onboarding')} /> )} {currentView === 'onboarding' && ( setCurrentView('landing')} /> )} {currentView === 'listen' && ( )} {currentView === 'talkback' && ( )} {currentView === 'timeline' && ( )} {currentView === 'insights' && ( )}
{/* Footer */}
); }