Skip to content

Commit 16b2e6e

Browse files
committed
implemented mystery box animation in tracks section only playing once per session
1 parent b8433f9 commit 16b2e6e

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

src/app/HomePage.tsx

Lines changed: 3 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,7 @@ 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 noTrackAnimation={noTrackAnimation} />
185187
</div>
186188

187189
<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/TrackSection.tsx

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

2424
import LivePoll from "./(AboutSectionComponents)/LivePoll";
25+
import { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
26+
import { actionSetTracksAnimation } from "@/src/util/actions/animation";
2527

26-
const TracksSection = () => {
28+
const TracksSection = ({ noTrackAnimation }: { noTrackAnimation: boolean }) => {
2729
const panelMargin = "mt-12 md:mt-16";
2830

2931
// tracks contains all relevant information about each of the 6 tracks
@@ -34,13 +36,10 @@ const TracksSection = () => {
3436
const selectedTrackRef = useRef<HTMLDivElement | null>(null);
3537
const livePollRef = useRef<HTMLDivElement | null>(null);
3638

37-
const [noAnimation, setNoAnimation] = useState<boolean>(
38-
sessionStorage.getItem("hackathonTracksShown") !== null,
39-
);
4039
const [startAnimation, setStartAnimation] = useState(false);
4140

4241
useEffect(() => {
43-
if (noAnimation) {
42+
if (noTrackAnimation) {
4443
return;
4544
}
4645

@@ -129,13 +128,12 @@ const TracksSection = () => {
129128
duration: 0.3,
130129
opacity: 1,
131130
onComplete: () => {
132-
// set session storage to prevent animation from playing again
133-
sessionStorage.setItem("hackathonTracksShown", "true");
134-
setNoAnimation(true);
131+
// set cookies storage to prevent animation from playing again
132+
actionSetTracksAnimation();
135133
},
136134
});
137135
}
138-
}, [showTracks, noAnimation]);
136+
}, [showTracks, noTrackAnimation]);
139137

140138
return (
141139
<Panel id="tracksPanel" className={panelMargin} panelColor="white">
@@ -149,7 +147,7 @@ const TracksSection = () => {
149147
</PanelHeader>
150148

151149
<div ref={panelContentRef}>
152-
{!noAnimation && (
150+
{!noTrackAnimation && (
153151
<PanelContent
154152
parentPanelId="tracksPanel"
155153
className="relative flex flex-col items-center"

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)