From 7ac10ce64fcc193bc8ddad812afbdfc5c580dd02 Mon Sep 17 00:00:00 2001 From: shahanneda Date: Sun, 30 Jan 2022 02:08:57 -0800 Subject: [PATCH] setup warning fetching on client side --- components/WarningHeader.tsx | 28 +++++++++++++++------ content/warnings/2022-01-29-testWarning.txt | 6 +++++ 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 content/warnings/2022-01-29-testWarning.txt diff --git a/components/WarningHeader.tsx b/components/WarningHeader.tsx index 9b816762..cfa7cc1f 100644 --- a/components/WarningHeader.tsx +++ b/components/WarningHeader.tsx @@ -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() { // 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 ( -
- Warning: The computers will be down for a scheduled maintenance unitl Jan - 28, 2021. -
- ); + const [warning, setWarning] = useState(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
{warning.content}
; } diff --git a/content/warnings/2022-01-29-testWarning.txt b/content/warnings/2022-01-29-testWarning.txt new file mode 100644 index 00000000..886c3ed3 --- /dev/null +++ b/content/warnings/2022-01-29-testWarning.txt @@ -0,0 +1,6 @@ +--- +startDate: 'January 29 2022 21:00' +endDate: 'January 30 2022 18:00' +--- +This is a test warning. Again! +