import { useEffect, useState } from 'react' import { useNavigate, useLocation } from 'react-router-dom' import { fetchMyChallenges } from '../api/challenges' import { useChallengeStore } from '../store/challengeStore' import { useUIStore } from '../store/uiStore' import type { ChallengeDetail } from '../types/api' import styles from './ChallengesListPanel.module.css' /** Full-page side panel for My Challenges — rendered outside CesiumViewer. */ export function MyChallengesSidePanel() { const { showMyChallenges, setShowMyChallenges } = useUIStore() const { setSelectedChallengeId } = useChallengeStore() const navigate = useNavigate() const location = useLocation() const [challenges, setChallenges] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) useEffect(() => { if (!showMyChallenges) return setLoading(true) setError(null) fetchMyChallenges() .then(setChallenges) .catch(() => setError('Failed to load your challenges.')) .finally(() => setLoading(false)) }, [showMyChallenges]) if (!showMyChallenges) return null function handleSelect(id: string) { setSelectedChallengeId(id) setShowMyChallenges(false) if (location.pathname !== '/') navigate('/') } return (
setShowMyChallenges(false)}>
e.stopPropagation()}>

My Challenges

{loading &&

Loading…

} {error &&

{error}

} {!loading && !error && challenges.length === 0 && (

You haven't created any challenges yet.

)} {challenges.map((c) => (
handleSelect(c.id)}> {c.title}
{c.status} {c.submission_count} submission{c.submission_count !== 1 ? 's' : ''} {c.expires_at && ( {new Date(c.expires_at) < new Date() ? 'Expired' : `Expires ${new Date(c.expires_at).toLocaleDateString()}`} )}
))}
) }