diff --git a/front_end/src/app/(main)/(tournaments)/tournaments/components/tournaments_filter.tsx b/front_end/src/app/(main)/(tournaments)/tournaments/components/tournaments_filter.tsx index a025900381..9698b62542 100644 --- a/front_end/src/app/(main)/(tournaments)/tournaments/components/tournaments_filter.tsx +++ b/front_end/src/app/(main)/(tournaments)/tournaments/components/tournaments_filter.tsx @@ -12,11 +12,10 @@ import { TOURNAMENTS_SORT } from "../constants/query_params"; const TournamentsFilter: React.FC = () => { const t = useTranslations(); - const { closeInfo } = useTournamentsSection(); + const { closeInfo, defaultSort } = useTournamentsSection(); const { params, setParam, shallowNavigateToSearchParams } = useSearchParams(); const sortBy = - (params.get(TOURNAMENTS_SORT) as TournamentsSortBy) ?? - TournamentsSortBy.Featured; + (params.get(TOURNAMENTS_SORT) as TournamentsSortBy) ?? defaultSort; const sortOptions: SelectOption[] = [ { value: TournamentsSortBy.Featured, label: t("featured") }, diff --git a/front_end/src/app/(main)/(tournaments)/tournaments/components/tournaments_provider.tsx b/front_end/src/app/(main)/(tournaments)/tournaments/components/tournaments_provider.tsx index 410592fd3d..40edd1c1e9 100644 --- a/front_end/src/app/(main)/(tournaments)/tournaments/components/tournaments_provider.tsx +++ b/front_end/src/app/(main)/(tournaments)/tournaments/components/tournaments_provider.tsx @@ -2,7 +2,7 @@ import React, { createContext, useContext, useMemo, useState } from "react"; -import { TournamentPreview } from "@/types/projects"; +import { TournamentPreview, TournamentsSortBy } from "@/types/projects"; import { selectTournamentsForSection } from "../helpers"; import { useTournamentFilters } from "../hooks/use_tournament_filters"; @@ -13,6 +13,7 @@ type TournamentsSectionCtxValue = { items: TournamentPreview[]; count: number; nowTs?: number; + defaultSort: TournamentsSortBy; infoOpen: boolean; toggleInfo: () => void; closeInfo: () => void; @@ -31,12 +32,18 @@ export function TournamentsSectionProvider(props: { const { tournaments, current, children, nowTs } = props; const [infoOpen, setInfoOpen] = useState(true); + const defaultSort = + current === "archived" + ? TournamentsSortBy.StartDateDesc + : TournamentsSortBy.Featured; + const sectionItems = useMemo( () => selectTournamentsForSection(tournaments, current), [tournaments, current] ); - const { filtered } = useTournamentFilters(sectionItems); + const filterOpts = useMemo(() => ({ defaultSort }), [defaultSort]); + const { filtered } = useTournamentFilters(sectionItems, filterOpts); const value = useMemo( () => ({ @@ -45,10 +52,11 @@ export function TournamentsSectionProvider(props: { count: filtered.length, infoOpen, nowTs, + defaultSort, toggleInfo: () => setInfoOpen((v) => !v), closeInfo: () => setInfoOpen(false), }), - [current, filtered, infoOpen, nowTs] + [current, filtered, infoOpen, nowTs, defaultSort] ); return ( diff --git a/front_end/src/app/(main)/(tournaments)/tournaments/hooks/use_tournament_filters.ts b/front_end/src/app/(main)/(tournaments)/tournaments/hooks/use_tournament_filters.ts index 70d72b70a8..6cd4779745 100644 --- a/front_end/src/app/(main)/(tournaments)/tournaments/hooks/use_tournament_filters.ts +++ b/front_end/src/app/(main)/(tournaments)/tournaments/hooks/use_tournament_filters.ts @@ -3,12 +3,13 @@ import { useMemo } from "react"; import useSearchParams from "@/hooks/use_search_params"; -import { TournamentPreview } from "@/types/projects"; +import { TournamentPreview, TournamentsSortBy } from "@/types/projects"; import { filterTournamentsFromParams } from "../helpers/tournament_filters"; type Options = { disableClientSort?: boolean; + defaultSort?: TournamentsSortBy; }; export function useTournamentFilters(