Skip to content

Commit aee9c02

Browse files
committed
pop up added
1 parent 0ad0961 commit aee9c02

File tree

3 files changed

+73
-6
lines changed

3 files changed

+73
-6
lines changed

pages/graveyard.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TopThree } from "../components/leaderboard/TopThree";
55
import { LeaderboardTable } from "../components/leaderboard/LeaderboardTable";
66
import { Item } from "../typings/types";
77
import tombstone from "../public/assets/animations/tombstone.json";
8+
import { motion, AnimatePresence } from "framer-motion";
89

910
// Dynamically import Lottie to prevent SSR issues
1011
const Lottie = dynamic(() => import("lottie-react"), { ssr: false });
@@ -13,9 +14,11 @@ function Graveyard() {
1314
const [leaderboard, setLeaderboard] = useState<Item[]>([]);
1415
const [loading, setLoading] = useState<boolean>(true);
1516
const [isClient, setIsClient] = useState(false);
17+
const [showNotification, setShowNotification] = useState<boolean>(false);
1618

1719
useEffect(() => {
18-
setIsClient(true); // Ensures animations only run on the client
20+
setIsClient(true);
21+
1922
const fetchGraveyardData = async () => {
2023
try {
2124
const baseURL = process.env.NEXT_PUBLIC_API_BASE_URL;
@@ -31,11 +34,41 @@ function Graveyard() {
3134
setLoading(false);
3235
}
3336
};
37+
38+
// Initial fetch
3439
fetchGraveyardData();
40+
41+
// Show notification on page load
42+
setShowNotification(true);
43+
setTimeout(() => setShowNotification(false), 4000);
44+
45+
// Refresh leaderboard every 5 minutes and show notification
46+
const interval = setInterval(() => {
47+
fetchGraveyardData();
48+
setShowNotification(true);
49+
setTimeout(() => setShowNotification(false), 4000);
50+
}, 5 * 60 * 1000); // 5 minutes
51+
52+
return () => clearInterval(interval);
3553
}, []);
3654

3755
return (
3856
<PageLayout title="PWOC | Graveyard" description="A place to bury programming mistakes">
57+
{/* 🔔 Notification Popup */}
58+
<AnimatePresence>
59+
{showNotification && (
60+
<motion.div
61+
initial={{ opacity: 0, x: 50 }}
62+
animate={{ opacity: 1, x: 0 }}
63+
exit={{ opacity: 0, x: 50 }}
64+
transition={{ duration: 0.5 }}
65+
className="fixed top-6 right-6 bg-white/20 text-white py-3 px-5 rounded-lg shadow-lg backdrop-blur-md border border-gray-400 z-50"
66+
>
67+
<p className="text-sm font-medium">🔄 Leaderboard refreshes every 5 minutes.</p>
68+
</motion.div>
69+
)}
70+
</AnimatePresence>
71+
3972
<div className="flex flex-col items-center my-[30px] w-full">
4073
<div className="font-bold text-[40px] text-[#274495]">Graveyard</div>
4174
<div className="text-[#274495] font-semibold">
@@ -59,4 +92,4 @@ function Graveyard() {
5992
);
6093
}
6194

62-
export default Graveyard;
95+
export default Graveyard;

pages/leaderboard.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { useEffect, useState } from "react";
33
import dynamic from "next/dynamic";
44
import { Item } from "../typings/types";
55
import { LeaderboardTable } from "../components/leaderboard/LeaderboardTable";
6-
import {TopThree} from "../components/leaderboard/TopThree";
6+
import { TopThree } from "../components/leaderboard/TopThree";
77
import PageLayout from "../components/layout/PageLayout";
88
import snowman from "../public/assets/animations/snowman.json";
9+
import { motion, AnimatePresence } from "framer-motion";
910

1011
// Dynamically import Lottie to prevent SSR issues
1112
const Lottie = dynamic(() => import("lottie-react"), { ssr: false });
@@ -14,9 +15,11 @@ const Leaderboard: NextPage = () => {
1415
const [leaderboard, setLeaderboard] = useState<Item[]>([]);
1516
const [loading, setLoading] = useState<boolean>(true);
1617
const [isClient, setIsClient] = useState(false);
18+
const [showNotification, setShowNotification] = useState<boolean>(false);
1719

1820
useEffect(() => {
19-
setIsClient(true); // Ensure animations only run on the client
21+
setIsClient(true);
22+
2023
const fetchLeaderboard = async () => {
2124
try {
2225
const baseURL = process.env.NEXT_PUBLIC_API_BASE_URL;
@@ -32,11 +35,42 @@ const Leaderboard: NextPage = () => {
3235
setLoading(false);
3336
}
3437
};
38+
39+
// Initial fetch
3540
fetchLeaderboard();
41+
42+
// Show notification on page load
43+
setShowNotification(true);
44+
setTimeout(() => setShowNotification(false), 4000);
45+
46+
// Refresh leaderboard every 5 minutes and show notification
47+
const interval = setInterval(() => {
48+
fetchLeaderboard();
49+
setShowNotification(true);
50+
setTimeout(() => setShowNotification(false), 4000);
51+
}, 5 * 60 * 1000); // 5 minutes
52+
53+
return () => clearInterval(interval);
3654
}, []);
3755

3856
return (
3957
<PageLayout title="PWOC | Leaderboard" description="Leaderboard of PWoC">
58+
{/* 🔔 Notification Popup */}
59+
<AnimatePresence>
60+
{showNotification && (
61+
<motion.div
62+
initial={{ opacity: 0, x: 50 }}
63+
animate={{ opacity: 1, x: 0 }}
64+
exit={{ opacity: 0, x: 50 }}
65+
transition={{ duration: 0.5 }}
66+
className="fixed top-6 right-6 bg-white/20 text-white py-3 px-5 rounded-lg shadow-lg backdrop-blur-md border border-gray-400 z-50"
67+
>
68+
<p className="text-sm font-medium">🔄 Leaderboard refreshes every 5 minutes.</p>
69+
</motion.div>
70+
)}
71+
</AnimatePresence>
72+
73+
{/* Leaderboard Content */}
4074
<div className="flex items-center flex-col">
4175
{leaderboard.length > 2 ? (
4276
<>
@@ -56,4 +90,4 @@ const Leaderboard: NextPage = () => {
5690
);
5791
};
5892

59-
export default Leaderboard;
93+
export default Leaderboard;

public/sw.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)