Warning Header (Closes #205) #394

Merged
snedadah merged 19 commits from warning-header into main 2022-02-22 23:29:55 -05:00
2 changed files with 26 additions and 8 deletions
Showing only changes of commit 7ac10ce64f - Show all commits

View File

@ -1,6 +1,6 @@
import { GetStaticProps } from "next";
import { getCurrentWarning, Warning } from "pages/api/warnings";
import React from "react";
import { Warning } from "pages/api/currentWarning";
import React, { useState, useEffect } from "react";
import { getCurrentTerm } from "@/lib/events";
@ -8,10 +8,22 @@ import styles from "./WarningHeader.module.css";
export function WarningHeader() {
snedadah marked this conversation as resolved
Review

We should probably move these functions to utils in that case, and then make both events and this file import from there

We should probably move these functions to utils in that case, and then make both events and this file import from there
// We can't use getStaticProps since its a component, and we can't put it getStaticProps in its parents because nextjs doesnt support it in the _app.js
return (
<div className={styles.warning}>
Warning: The computers will be down for a scheduled maintenance unitl Jan
28, 2021.
</div>
);
const [warning, setWarning] = useState<Warning | null>(null);
useEffect(() => {
fetch("api/currentWarning/")
.then((res) => res.json())
.then((data) => {
setWarning(data);
})
.catch((err) => {
console.error(err);
});
});
if (!warning || !warning.content || warning.content == "") {
return <></>;
}
return <div className={styles.warning}>{warning.content}</div>;
snedadah marked this conversation as resolved
Review

Do we really need this comment here? I personally think the comment on line 25, along with the general structure of the code, are already sufficient to convey what is happening and why.

Do we really need this comment here? I personally think the comment on line 25, along with the general structure of the code, are already sufficient to convey what is happening and why.
}

View File

@ -0,0 +1,6 @@
---
startDate: 'January 29 2022 21:00'
endDate: 'January 30 2022 18:00'
---
This is a test warning. Again!