From 9da8ef8dcbe2f479ad11bdcc2136893b066d9c30 Mon Sep 17 00:00:00 2001 From: Matthew Rowland Date: Mon, 23 Dec 2024 16:57:26 -0800 Subject: [PATCH] feat: futureTerm --- apps/frontend/src/app/Catalog/index.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/frontend/src/app/Catalog/index.tsx b/apps/frontend/src/app/Catalog/index.tsx index 50073bcd4..41a6b8f75 100644 --- a/apps/frontend/src/app/Catalog/index.tsx +++ b/apps/frontend/src/app/Catalog/index.tsx @@ -2,6 +2,7 @@ import { useCallback, useMemo, useState } from "react"; import classNames from "classnames"; import { Xmark } from "iconoir-react"; +import moment from "moment"; import { useLocation, useNavigate, useParams } from "react-router-dom"; import { IconButton } from "@repo/theme"; @@ -47,14 +48,21 @@ export default function Catalog() { const term = useMemo(() => { if (!terms) return null; - const currentTerm = terms?.find( + // Default to the current term + const currentTerm = terms.find( (term) => term.temporalPosition === TemporalPosition.Current ); - // Default to the current term + // Fall back to the next term when the current term has ended + const nextTerm = terms + .filter((term) => term.startDate) + .toSorted((a, b) => moment(a.startDate).diff(moment(b.startDate))) + .find((term) => term.temporalPosition === TemporalPosition.Future); + return ( terms?.find((term) => term.year === year && term.semester === semester) ?? - currentTerm + currentTerm ?? + nextTerm ); }, [terms, year, semester]);