import { useMemo, useState } from 'react'; import { Gallery } from './components/Gallery.jsx'; import { SightingMap } from './components/SightingMap.jsx'; import { AddSighting } from './components/AddSighting.jsx'; import { SightingDetail } from './components/SightingDetail.jsx'; import { useAuth, useCollection } from '@deplixo/sdk'; // PROGRESS:sc_001:complete:Setting up your nature journal function App() { const { user, loading, logout } = useAuth(); const [activeTab, setActiveTab] = useState('gallery'); const [showAddModal, setShowAddModal] = useState(false); const [selectedSighting, setSelectedSighting] = useState(null); const [searchQuery, setSearchQuery] = useState(''); const collection = useCollection('sightings', { personal: true }); const tabs = [ { id: 'gallery', label: 'Gallery', icon: '🌿' }, { id: 'map', label: 'Map', icon: 'πŸ—ΊοΈ' }, ]; const normalizedQuery = searchQuery.trim().toLowerCase(); const filteredSightings = useMemo(() => { const items = collection.items || []; if (!normalizedQuery) return items; return items.filter(item => { const name = `${item.name || ''} ${item.plantName || ''} ${item.commonName || ''}`.toLowerCase(); const location = `${item.location || ''} ${item.address || ''} ${item.place || ''} ${item.city || ''} ${item.region || ''}`.toLowerCase(); return name.includes(normalizedQuery) || location.includes(normalizedQuery); }); }, [collection.items, normalizedQuery]); const filteredCollection = { ...collection, items: filteredSightings, count: filteredSightings.length, }; const handleSelectSighting = sighting => { setSelectedSighting(sighting); }; if (loading) { return (
🌱

Nature Journal

Signing you in...

); } if (!user) { return (
🌿

Nature Journal

Sign in with Google to keep your sightings and journal entries personal.

e.preventDefault()}> Continue with Google

Google sign-in is handled by Deplixo auth.

); } return (

🌱 Nature Journal

Document your botanical discoveries

{(user.name || 'U').slice(0, 1).toUpperCase()} {user.name}
πŸ”Ž setSearchQuery(e.target.value)} placeholder="Search plant name or location" aria-label="Search plant name or location" /> {searchQuery && ( )}
{normalizedQuery ? `${filteredSightings.length} result${filteredSightings.length === 1 ? '' : 's'}` : `${collection.count || 0} sighting${(collection.count || 0) === 1 ? '' : 's'}`}
{normalizedQuery && filteredSightings.length === 0 && (
🌱

No matching sightings

Try a different plant name or location keyword.

)} {!normalizedQuery || filteredSightings.length > 0 ? ( <> {activeTab === 'gallery' && ( )} {activeTab === 'map' && ( )} ) : null}
{showAddModal && setShowAddModal(false)} />} {selectedSighting && ( setSelectedSighting(null)} /> )}
); } ReactDOM.createRoot(document.getElementById('root')).render();