import { useEffect, useState } from 'react'; import { supabase } from '../supabaseClient'; import { BookOpen, Map, Flame, LogOut, RefreshCw, Trophy, User } from 'lucide-react'; interface SidebarProps { activeTab: 'queue' | 'journey'; setActiveTab: (tab: 'queue' | 'journey') => void; user: any; } export default function Sidebar({ activeTab, setActiveTab, user }: SidebarProps) { const [streak, setStreak] = useState(null); const [syncing, setSyncing] = useState(false); const [syncResult, setSyncResult] = useState(null); const fetchStreak = async () => { try { const { data: { session } } = await supabase.auth.getSession(); if (!session) return; const res = await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/streak`, { headers: { 'Authorization': `Bearer ${session.access_token}` } }); if (res.ok) { const data = await res.json(); setStreak(data); } } catch (err) { console.error('Error fetching streak:', err); } }; useEffect(() => { fetchStreak(); }, [user]); const handleSync = async () => { setSyncing(true); setSyncResult(null); try { const { data: { session } } = await supabase.auth.getSession(); if (!session) return; const res = await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/sync`, { method: 'POST', headers: { 'Authorization': `Bearer ${session.access_token}` } }); if (res.ok) { const data = await res.json(); setSyncResult(data.message || 'Sync complete!'); // Refresh streak and state fetchStreak(); } else { setSyncResult('Sync failed. Check backend logs.'); } } catch (err) { setSyncResult('Sync failed. Server unreachable.'); } finally { setSyncing(false); } }; const handleSignOut = async () => { await supabase.auth.signOut(); }; return ( ); }