Skip to content

Commit 6713df6

Browse files
Merge pull request #181 from UWB-ACM/pgobin/tracks-section
made mystery box animation play only once per session
2 parents 5a7e0ab + a536a98 commit 6713df6

7 files changed

Lines changed: 57 additions & 24 deletions

File tree

src/app/HomePage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import { LeaderboardRecord, Prize } from "@/src/util/dataTypes";
2121
export default function HomePage({
2222
hackeroonPrizes,
2323
leaderboardData,
24+
noTrackAnimation,
2425
}: {
2526
hackeroonPrizes: Promise<Prize[]>;
2627
leaderboardData: Promise<LeaderboardRecord[]>;
28+
noTrackAnimation: boolean;
2729
}) {
2830
const mainRef = useRef<HTMLDivElement>(null);
2931
const aboutRef = useRef<HTMLDivElement>(null);
@@ -181,7 +183,9 @@ export default function HomePage({
181183

182184
{/* TODO - release all of these the day of the event */}
183185
<div id="tracks" ref={tracksRef} className="w-full">
184-
<TracksSection />
186+
<TracksSection
187+
noTrackAnimation={noTrackAnimation}
188+
/>
185189
</div>
186190

187191
<div

src/app/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import HomePage from "@/src/app/HomePage";
22
import { getPrizes } from "@/src/util/db/prize";
33
import { getLeaderboard } from "../util/db/leaderboard";
4+
import { cookies } from "next/headers";
45

56
export default async function Page() {
67
// The catch is to let this work in builds without databases.
@@ -14,10 +15,14 @@ export default async function Page() {
1415
return [];
1516
});
1617

18+
const reqCookies = await cookies();
19+
const noTrackAnimation = reqCookies.has("hackathonTracksShown");
20+
1721
return (
1822
<HomePage
1923
hackeroonPrizes={hackeroonPrizes}
2024
leaderboardData={leaderboardData}
25+
noTrackAnimation={noTrackAnimation}
2126
/>
2227
);
2328
}

src/components/landing-page/(TracksSectionComponents)/MysteryBox.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ export default function MysteryBox({
7575
duration: 0.3,
7676
ease: "power1.out",
7777
scale: 1,
78-
onComplete: () => setShowTracks(true),
78+
onComplete: () => {
79+
setShowTracks(true);
80+
},
7981
},
8082
"<",
8183
);
8284
});
8385
}
84-
}, [startAnimation]);
86+
}, [startAnimation, setShowTracks]);
8587

8688
return (
8789
<div ref={mysteryBoxRef} className="relative">

src/components/landing-page/(TracksSectionComponents)/TracksTabNavigation/SelectedTrackInformation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function SelectedTrackInformation({
1111
selectedTrack,
1212
}: SelectedTrackInformationProps) {
1313
return (
14-
<div ref={selectedTrackRef} className="space-y-4">
14+
<div ref={selectedTrackRef} className="space-y-4 p-4 md:p-12">
1515
<div>
1616
<p className="font-h2 font-bold tracking-wider text-center text-xl md:text-2xl">
1717
{selectedTrack.question}
@@ -20,7 +20,7 @@ export default function SelectedTrackInformation({
2020
{selectedTrack.description}
2121
</p>
2222
</div>
23-
<div className="flex flex-col md:flex-row justify-between gap-y-1 md:gap-x-6 lg:gap-x-4">
23+
<div className="flex flex-col md:flex-row justify-between gap-y-1 md:gap-x-6 lg:gap-x-4 max-w-[800px] mx-auto">
2424
<div className="md:w-1/2 text-center md:text-left">
2525
<p className="font-bold font-h2 text-lg md:text-xl text-[#49B2F8]">
2626
{selectedTrack.name + ": "} No Code Example

src/components/landing-page/(TracksSectionComponents)/TracksTabNavigation/TracksNav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function TracksNavHeader({
1717
return (
1818
<div
1919
ref={tracksNavRef}
20-
className="w-full flex flex-wrap items-center bg-black px-1 gap-1 md:px-2 md:gap-2 border-black border-y-4 md:border-y-8"
20+
className="z-[100] w-full flex flex-wrap items-center bg-black px-1 gap-1 md:px-2 md:gap-2 border-black border-y-4 md:border-y-8"
2121
>
2222
{tracks.map((track, idx) => (
2323
<button

src/components/landing-page/TrackSection.tsx

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import Tracks from "./(TracksSectionComponents)/TracksTabNavigation/Tracks";
2222
import { Track } from "@/src/util/dataTypes";
2323

2424
import LivePoll from "./(AboutSectionComponents)/LivePoll";
25+
import { actionSetTracksAnimation } from "@/src/util/actions/animation";
2526

26-
const TracksSection = () => {
27+
const TracksSection = ({ noTrackAnimation }: { noTrackAnimation: boolean }) => {
2728
const panelMargin = "mt-12 md:mt-16";
2829

2930
// tracks contains all relevant information about each of the 6 tracks
@@ -37,6 +38,10 @@ const TracksSection = () => {
3738
const [startAnimation, setStartAnimation] = useState(false);
3839

3940
useEffect(() => {
41+
if (noTrackAnimation) {
42+
return;
43+
}
44+
4045
// set initial animation state for tracks comp
4146
gsap.set(tracksNavRef.current, {
4247
height: 0,
@@ -121,9 +126,13 @@ const TracksSection = () => {
121126
}).to(livePollRef.current, {
122127
duration: 0.3,
123128
opacity: 1,
129+
onComplete: () => {
130+
// set cookies storage to prevent animation from playing again
131+
actionSetTracksAnimation();
132+
},
124133
});
125134
}
126-
}, [showTracks]);
135+
}, [showTracks, noTrackAnimation]);
127136

128137
return (
129138
<Panel id="tracksPanel" className={panelMargin} panelColor="white">
@@ -137,22 +146,26 @@ const TracksSection = () => {
137146
</PanelHeader>
138147

139148
<div ref={panelContentRef}>
140-
<PanelContent
141-
parentPanelId="tracksPanel"
142-
className="relative flex flex-col items-center"
143-
>
144-
<QuestionMark className="w-[65px] md:w-[80px] lg:w-[100px] xl:w-[125px] top-[10%] left-[8%] rotate-[19deg]" />
145-
<QuestionMark className="w-[65px] md:w-[80px] lg:w-[100px] xl:w-[125px] top-[20%] right-[14%] -rotate-[15deg]" />
146-
<QuestionMark className="w-[65px] md:w-[80px] lg:w-[100px] xl:w-[125px] bottom-[10%] left-[16%] rotate-[28deg]" />
147-
<QuestionMark className="w-[65px] md:w-[80px] lg:w-[100px] xl:w-[125px] bottom-[3%] right-[20%] -rotate-[40deg]" />
148-
149-
{/* Pass name of each track as contents of mystery box */}
150-
<MysteryBox
151-
contents={tracks.map((track) => track["name"])}
152-
startAnimation={startAnimation}
153-
setShowTracks={setShowTracks}
154-
/>
155-
</PanelContent>
149+
{!noTrackAnimation && (
150+
<PanelContent
151+
parentPanelId="tracksPanel"
152+
className="relative flex flex-col items-center"
153+
>
154+
<>
155+
<QuestionMark className="w-[65px] md:w-[80px] lg:w-[100px] xl:w-[125px] top-[10%] left-[8%] rotate-[19deg]" />
156+
<QuestionMark className="w-[65px] md:w-[80px] lg:w-[100px] xl:w-[125px] top-[20%] right-[14%] -rotate-[15deg]" />
157+
<QuestionMark className="w-[65px] md:w-[80px] lg:w-[100px] xl:w-[125px] bottom-[10%] left-[16%] rotate-[28deg]" />
158+
<QuestionMark className="w-[65px] md:w-[80px] lg:w-[100px] xl:w-[125px] bottom-[3%] right-[20%] -rotate-[40deg]" />
159+
</>
160+
161+
{/* Pass name of each track as contents of mystery box */}
162+
<MysteryBox
163+
contents={tracks.map((track) => track["name"])}
164+
startAnimation={startAnimation}
165+
setShowTracks={setShowTracks}
166+
/>
167+
</PanelContent>
168+
)}
156169
</div>
157170

158171
<Tracks

src/util/actions/animation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use server";
2+
3+
import { cookies } from "next/headers";
4+
5+
export async function actionSetTracksAnimation() {
6+
"use server";
7+
8+
(await cookies()).set("hackathonTracksShown", "true");
9+
}

0 commit comments

Comments
 (0)