From ae90848cfcde0d982a0a273bce6bbb25de87dba2 Mon Sep 17 00:00:00 2001 From: Leo <47073066+jaranmio@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:07:20 -0500 Subject: [PATCH] Not found page (#871) Co-authored-by: Lowell Torola --- frontend/src/components/CountdownDigital.tsx | 161 +++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 frontend/src/components/CountdownDigital.tsx diff --git a/frontend/src/components/CountdownDigital.tsx b/frontend/src/components/CountdownDigital.tsx new file mode 100644 index 000000000..b3ecb27f9 --- /dev/null +++ b/frontend/src/components/CountdownDigital.tsx @@ -0,0 +1,161 @@ +import type React from "react"; +import { useEffect, useMemo, useState } from "react"; + +const thousand = 1000; +const sixty = 60; +const hoursInDay = 24; +const fullPercentage = 100; +const countDownRefreshRate = 30; + +interface ProgressCircleProps { + sqSize: number; + percentage: number; +} + +const ProgressCircle: React.FC = ({ + sqSize, + percentage, +}) => { + const strokeWidth = 6; + const radius = (sqSize - strokeWidth) / 2; + const viewBox = `0 0 ${sqSize} ${sqSize}`; + const dashArray = radius * Math.PI * 2; + const dashOffset = dashArray - (dashArray * percentage) / fullPercentage; + + return ( + + + + + ); +}; + +interface DateParams { + days: number; + hours: number; + minutes: number; +} + +const computeTimeDiff = (fromDate: Date, toDate: Date): DateParams => { + const timeDiff = toDate.getTime() - fromDate.getTime(); + + const days = Math.floor(timeDiff / (thousand * sixty * sixty * hoursInDay)); + const hours = Math.floor( + (timeDiff % (thousand * sixty * sixty * hoursInDay)) / + (thousand * sixty * sixty), + ); + const minutes = Math.floor( + (timeDiff % (thousand * sixty * sixty)) / (thousand * sixty), + ); + + return { days, hours, minutes }; +}; + +interface CountdownDigitalProps { + date: Date; + title?: string; +} + +const CountdownDigital: React.FC = ({ date }) => { + const currentTime = new Date(); + const [count, setCount] = useState(0); + + useEffect(() => { + const intervalId = setInterval(() => { + setCount((prevCount) => prevCount + 1); + }, thousand * countDownRefreshRate); + return () => { + clearInterval(intervalId); + }; + }, []); + + const countdownInfo = useMemo( + () => computeTimeDiff(currentTime, date), + [count], + ); + const progressCircleSize = 140; + const percentageDays = + ((sixty - countdownInfo.days) / sixty) * fullPercentage; + const percentageHours = + ((hoursInDay - countdownInfo.hours) / hoursInDay) * fullPercentage; + const percentageMins = + ((sixty - countdownInfo.minutes) / sixty) * fullPercentage; + const countTxtSize = "3xl"; + const labelTxtSize = "l"; + + return ( +
+
+ {ProgressCircle({ + sqSize: progressCircleSize, + percentage: percentageDays, + })} + +
+ + {countdownInfo.days} + + Days +
+
+
+ {ProgressCircle({ + sqSize: progressCircleSize, + percentage: percentageHours, + })} + +
+ + {countdownInfo.hours} + + Hours +
+
+
+ {ProgressCircle({ + sqSize: progressCircleSize, + percentage: percentageMins, + })} + +
+ + {countdownInfo.minutes} + + Mins +
+
+
+ ); +}; + +export default CountdownDigital;