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