import React, { useState, useEffect } from 'react'; import { Button } from '../ui/button'; import { SearchInput } from '../ui/input'; import { AchievementCard } from './AchievementCard'; import { Achievement } from '../../types'; import { Trophy, Lock, CheckCircle, Loader2 } from 'lucide-react'; import { gamificationService } from '../../services/gamificationService'; import { logger } from '@/utils/logger'; export const AchievementsView: React.FC = () => { const [filter, setFilter] = useState<'all' | 'earned' | 'locked'>('all'); const [search, setSearch] = useState(''); const [achievements, setAchievements] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchData = async () => { setLoading(true); try { const data = await gamificationService.getAchievements('me'); setAchievements(data); } catch (e) { logger.error('Error loading achievements', { error: e instanceof Error ? e.message : String(e), stack: e instanceof Error ? e.stack : undefined, }); } finally { setLoading(false); } }; fetchData(); }, []); const filtered = achievements.filter((ach) => { const matchSearch = ach.name.toLowerCase().includes(search.toLowerCase()); const isEarned = ach.progress >= ach.maxProgress; if (filter === 'earned') return matchSearch && isEarned; if (filter === 'locked') return matchSearch && !isEarned; return matchSearch; }); const earnedCount = achievements.filter( (a) => a.progress >= a.maxProgress, ).length; if (loading) return (
); return (
{/* Header */}

ACHIEVEMENTS

Track your milestones and earn rewards.

{earnedCount} / {achievements.length} Unlocked
{/* Controls */}
setSearch(e.target.value)} />
{/* Grid */}
{filtered.map((ach) => ( ))}
); };