mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-22 20:16:57 +00:00
Fix date filter
bis bis
This commit is contained in:
@@ -138,7 +138,6 @@ const getTournaments = async () => {
|
||||
town: t.town,
|
||||
department: t.department,
|
||||
date: t.date,
|
||||
isoDate: formatISO(date),
|
||||
url: t.url,
|
||||
timeControl,
|
||||
latLng: { lat: t.coordinates[0], lng: t.coordinates[1] },
|
||||
|
||||
+28
-12
@@ -1,7 +1,16 @@
|
||||
import { formatISO, setDefaultOptions } from "date-fns";
|
||||
import {
|
||||
endOfDay,
|
||||
formatISO,
|
||||
isAfter,
|
||||
isBefore,
|
||||
parse,
|
||||
setDefaultOptions,
|
||||
startOfDay,
|
||||
} from "date-fns";
|
||||
import { fr } from "date-fns/locale";
|
||||
import { atom } from "jotai";
|
||||
import { LatLngBounds } from "leaflet";
|
||||
import { c } from "next-safe-action/dist/index-EKyvnpX_.mjs";
|
||||
|
||||
import { Club, TimeControl, Tournament } from "@/types";
|
||||
import atomWithDebounce from "@/utils/atomWithDebounce";
|
||||
@@ -41,23 +50,27 @@ export const filteredTournamentsByTimeControlAtom = atom((get) => {
|
||||
const other = get(otherAtom);
|
||||
|
||||
const dateRange = get(dateRangeAtom);
|
||||
const startDate = formatISO(dateRange[0].startDate);
|
||||
const endDate =
|
||||
dateRange[0].endDate !== undefined
|
||||
? formatISO(dateRange[0].endDate)
|
||||
: undefined;
|
||||
const { startDate, endDate } = dateRange[0];
|
||||
|
||||
return tournaments.filter(
|
||||
(tournament) =>
|
||||
tournament.isoDate >= startDate &&
|
||||
(endDate === undefined || tournament.isoDate <= endDate) &&
|
||||
const filteredTournaments = tournaments.filter((tournament) => {
|
||||
const tournamentDate = startOfDay(
|
||||
parse(tournament.date, "dd/MM/yyyy", new Date()),
|
||||
);
|
||||
|
||||
return (
|
||||
!isBefore(tournamentDate, startDate) &&
|
||||
(endDate === undefined ||
|
||||
(!isAfter(tournamentDate, endDate) &&
|
||||
!tournament.pending &&
|
||||
tournament.status === "scheduled" &&
|
||||
((tournament.timeControl === TimeControl.Classic && classic) ||
|
||||
(tournament.timeControl === TimeControl.Rapid && rapid) ||
|
||||
(tournament.timeControl === TimeControl.Blitz && blitz) ||
|
||||
(tournament.timeControl === TimeControl.Other && other)),
|
||||
(tournament.timeControl === TimeControl.Other && other))))
|
||||
);
|
||||
});
|
||||
|
||||
return filteredTournaments;
|
||||
});
|
||||
|
||||
export const filteredTournamentsListAtom = atom((get) => {
|
||||
@@ -116,7 +129,10 @@ export const datePickerIsOpenAtom = atom(false);
|
||||
|
||||
export const maxDateAtom = atom((get) => {
|
||||
const tournaments = get(tournamentsAtom);
|
||||
const dateTimestamps = tournaments.map((t) => new Date(t.isoDate).getTime());
|
||||
const dateTimestamps = tournaments.map((t) =>
|
||||
endOfDay(parse(t.date, "dd/MM/yyyy", new Date())).getTime(),
|
||||
);
|
||||
|
||||
return new Date(Math.max(...dateTimestamps));
|
||||
});
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ export type Tournament = {
|
||||
url: string;
|
||||
timeControl: TimeControl;
|
||||
date: string;
|
||||
isoDate: string;
|
||||
latLng: LatLngLiteral;
|
||||
norm: boolean;
|
||||
pending: boolean;
|
||||
|
||||
Reference in New Issue
Block a user