|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useState, useEffect, useMemo } from 'react'; |
| 4 | +import { useRouter, useSearchParams, useParams } from 'next/navigation'; |
| 5 | +import { useHackathonData } from '@/lib/providers/hackathonProvider'; |
| 6 | + |
| 7 | +import { HackathonBanner } from '@/components/hackathons/hackathonBanner'; |
| 8 | +import { HackathonNavTabs } from '@/components/hackathons/hackathonNavTabs'; |
| 9 | +import { HackathonOverview } from '@/components/hackathons/overview/hackathonOverview'; |
| 10 | +import { HackathonParticipants } from '@/components/hackathons/participants/hackathonParticipant'; |
| 11 | +import { HackathonResources } from '@/components/hackathons/resources/resources'; |
| 12 | +import SubmissionTab from '@/components/hackathons/submissions/submissionTab'; |
| 13 | +import { HackathonDiscussions } from '@/components/hackathons/discussion/comment'; |
| 14 | +import LoadingScreen from '@/components/landing-page/project/CreateProjectModal/LoadingScreen'; |
| 15 | + |
| 16 | +export default function HackathonPage() { |
| 17 | + const router = useRouter(); |
| 18 | + const searchParams = useSearchParams(); |
| 19 | + const params = useParams(); |
| 20 | + |
| 21 | + const { |
| 22 | + currentHackathon, |
| 23 | + content, |
| 24 | + timelineEvents, |
| 25 | + participants, |
| 26 | + submissions, |
| 27 | + prizes, |
| 28 | + loading, |
| 29 | + setCurrentHackathon, |
| 30 | + } = useHackathonData(); |
| 31 | + |
| 32 | + const hackathonTabs = useMemo( |
| 33 | + () => [ |
| 34 | + { id: 'overview', label: 'Overview' }, |
| 35 | + { id: 'participants', label: 'Participants', badge: participants.length }, |
| 36 | + { id: 'resources', label: 'Resources' }, |
| 37 | + { |
| 38 | + id: 'submission', |
| 39 | + label: 'Submissions', |
| 40 | + badge: submissions.filter(p => p.status === 'Approved').length, |
| 41 | + }, |
| 42 | + { id: 'discussions', label: 'Discussions' }, |
| 43 | + ], |
| 44 | + [participants.length, submissions] |
| 45 | + ); |
| 46 | + |
| 47 | + const hackathonId = params.slug as string; |
| 48 | + const [activeTab, setActiveTab] = useState('overview'); |
| 49 | + |
| 50 | + useEffect(() => { |
| 51 | + if (hackathonId) { |
| 52 | + setCurrentHackathon(hackathonId); |
| 53 | + } |
| 54 | + }, [hackathonId, setCurrentHackathon]); |
| 55 | + |
| 56 | + useEffect(() => { |
| 57 | + const tabFromUrl = searchParams.get('tab'); |
| 58 | + if (tabFromUrl && hackathonTabs.some(tab => tab.id === tabFromUrl)) { |
| 59 | + setActiveTab(tabFromUrl); |
| 60 | + } |
| 61 | + }, [searchParams, hackathonTabs]); |
| 62 | + |
| 63 | + const handleTabChange = (tabId: string) => { |
| 64 | + setActiveTab(tabId); |
| 65 | + const params = new URLSearchParams(searchParams.toString()); |
| 66 | + params.set('tab', tabId); |
| 67 | + router.push(`?${params.toString()}`, { scroll: false }); |
| 68 | + }; |
| 69 | + |
| 70 | + if (loading) { |
| 71 | + return <LoadingScreen />; |
| 72 | + } |
| 73 | + |
| 74 | + if (!currentHackathon) { |
| 75 | + return ( |
| 76 | + <div className='flex min-h-screen items-center justify-center'> |
| 77 | + <div className='text-center'> |
| 78 | + <h1 className='mb-4 text-2xl font-bold text-white'> |
| 79 | + Hackathon not found |
| 80 | + </h1> |
| 81 | + <p className='text-gray-400'> |
| 82 | + The hackathon you're looking for doesn't exist. |
| 83 | + </p> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + return ( |
| 90 | + <div className='mx-auto mt-10 max-w-[1440px] px-5 py-5 text-center text-4xl font-bold text-white md:px-[50px] lg:px-[100px]'> |
| 91 | + {/* Banner */} |
| 92 | + <HackathonBanner |
| 93 | + title={currentHackathon.title} |
| 94 | + subtitle={currentHackathon.subtitle} |
| 95 | + deadline={currentHackathon.deadline} |
| 96 | + categories={currentHackathon.categories} |
| 97 | + status={currentHackathon.status} |
| 98 | + participants={currentHackathon.participants} |
| 99 | + totalPrizePool={currentHackathon.totalPrizePool} |
| 100 | + imageUrl={currentHackathon.imageUrl} |
| 101 | + startDate={currentHackathon.startDate} // if upcoming |
| 102 | + /> |
| 103 | + |
| 104 | + {/* Tabs */} |
| 105 | + <HackathonNavTabs |
| 106 | + tabs={hackathonTabs} |
| 107 | + activeTab={activeTab} |
| 108 | + onTabChange={handleTabChange} |
| 109 | + /> |
| 110 | + |
| 111 | + {/* Content */} |
| 112 | + <div className='mx-auto max-w-7xl px-6 py-12 text-white'> |
| 113 | + {activeTab === 'overview' && ( |
| 114 | + <HackathonOverview |
| 115 | + content={content} |
| 116 | + timelineEvents={timelineEvents} |
| 117 | + prizes={prizes} |
| 118 | + /> |
| 119 | + )} |
| 120 | + |
| 121 | + {activeTab === 'participants' && <HackathonParticipants />} |
| 122 | + |
| 123 | + {activeTab === 'resources' && <HackathonResources />} |
| 124 | + |
| 125 | + {activeTab === 'submission' && <SubmissionTab />} |
| 126 | + |
| 127 | + {activeTab === 'discussions' && ( |
| 128 | + <HackathonDiscussions hackathonId={hackathonId} /> |
| 129 | + )} |
| 130 | + </div> |
| 131 | + </div> |
| 132 | + ); |
| 133 | +} |
0 commit comments