Skip to content

Commit

Permalink
Merge branch 'develop' into JUP-61-club-search-page
Browse files Browse the repository at this point in the history
  • Loading branch information
nl32 authored Oct 22, 2024
2 parents 2359f0a + 91d7678 commit f50bf79
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/components/events/EventTimeAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
differenceInMinutes,
} from 'date-fns';
import { type ReactNode } from 'react';
import { useState, useEffect } from 'react';

type EventTimeAlertProps = {
event: SelectEvent;
};

type BaseProps = { children: ReactNode; className?: string };
const Base = ({ children, className }: BaseProps) => {
return (
Expand All @@ -22,12 +24,23 @@ const Base = ({ children, className }: BaseProps) => {
</div>
);
};

const EventTimeAlert = ({ event }: EventTimeAlertProps) => {
const now = new Date();
const [now, setNow] = useState(Date.now());

useEffect(() => {
const intervalId = setInterval(() => {
setNow(Date.now());
}, 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() < now) {
if (event.endTime.getTime() < now) {
return <Base className="bg-red-600">over :(</Base>;
} else {
return <Base className="bg-green-600">NOW</Base>;
Expand Down

0 comments on commit f50bf79

Please sign in to comment.