From 3ccdaa962b6367381e3a304c1b43cc4e9508f753 Mon Sep 17 00:00:00 2001 From: MamounE1 Date: Tue, 1 Oct 2024 18:03:37 -0500 Subject: [PATCH 1/3] make event countdown work --- src/components/events/EventTimeAlert.tsx | 45 +++++++++++++++++++----- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/components/events/EventTimeAlert.tsx b/src/components/events/EventTimeAlert.tsx index c027f020..a0eee0fe 100644 --- a/src/components/events/EventTimeAlert.tsx +++ b/src/components/events/EventTimeAlert.tsx @@ -10,6 +10,7 @@ import { type ReactNode } from 'react'; type EventTimeAlertProps = { event: SelectEvent; }; + type BaseProps = { children: ReactNode; className?: string }; const Base = ({ children, className }: BaseProps) => { return ( @@ -22,19 +23,43 @@ const Base = ({ children, className }: BaseProps) => { ); }; -const EventTimeAlert = ({ event }: EventTimeAlertProps) => { - const now = new Date(); + +import React, {useState, useEffect} from 'react'; + +const EventTimeAlert = ({ event }: EventTimeAlertProps) => +{ + const [now, setNow] = useState(new Date()); + + useEffect(() => { + const intervalId = setInterval(() => + { + setNow (new Date()); + }, 1000); + + return () => clearInterval(intervalId); + + }, []); + const start = event.startTime; const hourDiff = differenceInHours(start, now); - if (event.startTime.getTime() < Date.now()) { - if (event.endTime.getTime() < Date.now()) { + + if (event.startTime.getTime() < Date.now()) + { + if (event.endTime.getTime() < Date.now()) + { return over :(; - } else { + } + else + { return NOW; } - } else { - if (differenceInDays(start, now) < 1) { - if (hourDiff < 1) { + } + else + { + if (differenceInDays(start, now) < 1) + { + if (hourDiff < 1) + { return ( {differenceInMinutes(start, now)} minutes @@ -45,7 +70,9 @@ const EventTimeAlert = ({ event }: EventTimeAlertProps) => { } else { return {hourDiff} hours; } - } else { + } + else + { return ( {differenceInDays(start, now)} days ); From 0fa39ba433f80a71f2648ee28c371cee826db7dd Mon Sep 17 00:00:00 2001 From: MamounE1 Date: Tue, 8 Oct 2024 18:37:54 -0500 Subject: [PATCH 2/3] Fixed the suggesions --- src/components/events/EventTimeAlert.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/events/EventTimeAlert.tsx b/src/components/events/EventTimeAlert.tsx index a0eee0fe..2dab2161 100644 --- a/src/components/events/EventTimeAlert.tsx +++ b/src/components/events/EventTimeAlert.tsx @@ -6,6 +6,7 @@ import { differenceInMinutes, } from 'date-fns'; import { type ReactNode } from 'react'; +import {useState, useEffect} from 'react'; type EventTimeAlertProps = { event: SelectEvent; @@ -24,16 +25,16 @@ const Base = ({ children, className }: BaseProps) => { ); }; -import React, {useState, useEffect} from 'react'; + const EventTimeAlert = ({ event }: EventTimeAlertProps) => { - const [now, setNow] = useState(new Date()); + const [now, setNow] = useState(Date.now()); useEffect(() => { const intervalId = setInterval(() => { - setNow (new Date()); + setNow (Date.now()); }, 1000); return () => clearInterval(intervalId); @@ -43,9 +44,9 @@ const EventTimeAlert = ({ event }: EventTimeAlertProps) => const start = event.startTime; const hourDiff = differenceInHours(start, now); - if (event.startTime.getTime() < Date.now()) + if (event.startTime.getTime() < now) { - if (event.endTime.getTime() < Date.now()) + if (event.endTime.getTime() < now) { return over :(; } From 70d5cb87c217d4656bd1206ed96a3e786dc46116 Mon Sep 17 00:00:00 2001 From: Ethan Bickel Date: Tue, 22 Oct 2024 12:53:51 -0500 Subject: [PATCH 3/3] fix formatting --- src/components/events/EventTimeAlert.tsx | 39 ++++++++---------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/components/events/EventTimeAlert.tsx b/src/components/events/EventTimeAlert.tsx index 2dab2161..be18211d 100644 --- a/src/components/events/EventTimeAlert.tsx +++ b/src/components/events/EventTimeAlert.tsx @@ -6,7 +6,7 @@ import { differenceInMinutes, } from 'date-fns'; import { type ReactNode } from 'react'; -import {useState, useEffect} from 'react'; +import { useState, useEffect } from 'react'; type EventTimeAlertProps = { event: SelectEvent; @@ -25,42 +25,29 @@ const Base = ({ children, className }: BaseProps) => { ); }; +const EventTimeAlert = ({ event }: EventTimeAlertProps) => { + const [now, setNow] = useState(Date.now()); - -const EventTimeAlert = ({ event }: EventTimeAlertProps) => -{ - const [now, setNow] = useState(Date.now()); - useEffect(() => { - const intervalId = setInterval(() => - { - setNow (Date.now()); + const intervalId = setInterval(() => { + setNow(Date.now()); }, 1000); return () => clearInterval(intervalId); - }, []); const start = event.startTime; const hourDiff = differenceInHours(start, now); - if (event.startTime.getTime() < now) - { - if (event.endTime.getTime() < now) - { + if (event.startTime.getTime() < now) { + if (event.endTime.getTime() < now) { return over :(; - } - else - { + } else { return NOW; } - } - else - { - if (differenceInDays(start, now) < 1) - { - if (hourDiff < 1) - { + } else { + if (differenceInDays(start, now) < 1) { + if (hourDiff < 1) { return ( {differenceInMinutes(start, now)} minutes @@ -71,9 +58,7 @@ const EventTimeAlert = ({ event }: EventTimeAlertProps) => } else { return {hourDiff} hours; } - } - else - { + } else { return ( {differenceInDays(start, now)} days );