From c48686277dc2e288323b311756dcb3db90bf20a7 Mon Sep 17 00:00:00 2001 From: Erik Vroon Date: Thu, 20 Feb 2025 18:43:10 +0100 Subject: [PATCH] Fix sorting of matches on dashboard (#1129) fixes https://github.com/evroon/bracket/issues/979 also reverses the order so it is now in ascending order from oldest to most recent match. --- frontend/src/components/utils/datetime.tsx | 4 ++++ frontend/src/pages/tournaments/[id]/dashboard/index.tsx | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/utils/datetime.tsx b/frontend/src/components/utils/datetime.tsx index a91d2300..d47c610d 100644 --- a/frontend/src/components/utils/datetime.tsx +++ b/frontend/src/components/utils/datetime.tsx @@ -13,3 +13,7 @@ export function Time({ datetime }: { datetime: string }) { export function formatTime(datetime: string) { return format(parseISO(datetime), 'HH:mm'); } + +export function compareDateTime(datetime1: string, datetime2: string) { + return parseISO(datetime1) > parseISO(datetime2); +} diff --git a/frontend/src/pages/tournaments/[id]/dashboard/index.tsx b/frontend/src/pages/tournaments/[id]/dashboard/index.tsx index b4dbaded..4b78d7ac 100644 --- a/frontend/src/pages/tournaments/[id]/dashboard/index.tsx +++ b/frontend/src/pages/tournaments/[id]/dashboard/index.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { DashboardFooter } from '../../../../components/dashboard/footer'; import { DoubleHeader, TournamentHeadTitle } from '../../../../components/dashboard/layout'; import { NoContent } from '../../../../components/no_content/empty_table_info'; -import { Time, formatTime } from '../../../../components/utils/datetime'; +import { Time, compareDateTime, formatTime } from '../../../../components/utils/datetime'; import { Translator } from '../../../../components/utils/types'; import { responseIsValid } from '../../../../components/utils/util'; import { formatMatchInput1, formatMatchInput2 } from '../../../../interfaces/match'; @@ -134,7 +134,7 @@ export function Schedule({ .filter((m1: any) => m1.match.start_time != null) .sort( (m1: any, m2: any) => - -formatTime(m1.match.start_time).localeCompare(formatTime(m2.match.start_time)) || + compareDateTime(m1.match.start_time, m2.match.start_time) || m1.match.court?.name.localeCompare(m2.match.court?.name) );