Skip to content

Commit

Permalink
feat: futureTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
mathhulk committed Dec 24, 2024
1 parent 7f47eb1 commit 9da8ef8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apps/frontend/src/app/Catalog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit 9da8ef8

Please sign in to comment.