From ef2b4dde885698c10a948cc2fdb97879b5ad448e Mon Sep 17 00:00:00 2001 From: Sarah John Date: Wed, 4 Dec 2024 20:34:28 -0500 Subject: [PATCH] warning if navigating to a past semester --- src/components/Header.tsx | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 6769330..cc046a8 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -25,7 +25,7 @@ import { createListCollection } from "@chakra-ui/react"; import { Term } from "../lib/dates"; import { State } from "../lib/state"; -import { useState, useRef } from "react"; +import { useState, useRef, useEffect } from "react"; import { COLOR_SCHEME_PRESETS } from "../lib/colors"; import { Preferences, DEFAULT_PREFERENCES } from "../lib/schema"; @@ -170,12 +170,26 @@ function getUrlNames(latestTerm: string): Array { /** Header above the left column, with logo and semester selection. */ export function Header(props: { state: State; preferences: Preferences }) { const { state, preferences } = props; + const [showDialog, setShowDialog] = useState(false); const logoSrc = useColorModeValue(logo, logoDark); const toUrl = (urlName: string) => toFullUrl(urlName, state.latestTerm.urlName); const defaultValue = toUrl(state.term.urlName); + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const term = urlParams.get("t"); + if (term && term !== state.latestTerm.urlName) { + setShowDialog(true); + } + }, [state.latestTerm.urlName]); + + const handleCloseDialog = () => { + setShowDialog(false); + }; + return ( + <> Hydrant logo + { + setShowDialog(details.open); + }} +> + + + Past Semester Warning + + + You are viewing a past semester. + + + + + + + + + ); }