Adding checking dates

This commit is contained in:
Théo 2023-04-22 13:11:49 +02:00
parent 354a527478
commit 5864a4c84b

View file

@ -42,6 +42,25 @@ export default function Puzzles({ token }: { token: string }) {
); );
} }
function isBetweenDates(chapter: Chapter) {
if (!chapter.startDate || !chapter.endDate) {
return false;
}
const startDate = new Date(chapter.startDate);
const endDate = new Date(chapter.endDate);
const now = new Date();
if (startDate < now && endDate > now) {
const minutes = 10 * 60 * 1000;
if (startDate.getTime() + minutes < now.getTime()) {
return true;
}
}
return false;
}
const filteredData = useMemo(() => { const filteredData = useMemo(() => {
if (filter && filterChapter) { if (filter && filterChapter) {
if (filter === 'completed' || filter === 'no-completed') { if (filter === 'completed' || filter === 'no-completed') {
@ -63,16 +82,6 @@ export default function Puzzles({ token }: { token: string }) {
return data?.find((chapter) => chapter.id === filterChapter)?.puzzles; return data?.find((chapter) => chapter.id === filterChapter)?.puzzles;
}, [data, filter, filterChapter]); }, [data, filter, filterChapter]);
useEffect(() => {
const { hash } = window.location;
if (hash) {
const element = document.querySelector(hash);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
}
}, []);
return ( return (
<> <>
{(!isLoading && {(!isLoading &&
@ -81,7 +90,7 @@ export default function Puzzles({ token }: { token: string }) {
<div className="flex flex-col justify-between md:flex-row md:items-center"> <div className="flex flex-col justify-between md:flex-row md:items-center">
<div className="flex items-center gap-x-2"> <div className="flex items-center gap-x-2">
<h1 className="text-xl font-semibold">{chapter.name}</h1> <h1 className="text-xl font-semibold">{chapter.name}</h1>
{!isInEventGroup(chapter) && ( {!isInEventGroup(chapter) && !isBetweenDates(chapter) && (
<Dialog <Dialog
key={chapter.id} key={chapter.id}
title={chapter.name} title={chapter.name}