From adb8b01355d5c1a766189ba7e709ef4323eb8d16 Mon Sep 17 00:00:00 2001 From: Kishan Date: Sun, 28 Feb 2021 12:37:26 +0000 Subject: [PATCH] MS1.5 Fix an issue where the site is wrong (#51) Fix #50 to ensure the site works: Issue was that we told the site to go forward 1 week on Sundays and Saturdays, which resulted in it skipping a week forward. This is because the algorithm works by rewinding to the last Sunday and going from there, so on Sundays it obviously stays on the current Sunday, and it was programmed to jump forward 7 days on Sundays Also adds a alert on Lateral Flow Testing & version bump Commits: * Change alert * Setup separate KECHG and KECHB alerts * Fixed an issue where date was wrong #50 Added alerts to holiday page * Bump version number * Remove date fiddling --- .vscode/launch.json | 23 +++++++++++++++++++++++ frontend/package.json | 2 +- frontend/src/App.tsx | 8 ++++++++ frontend/src/components/SiteContainer.tsx | 20 +++++++++++++------- frontend/src/data/alerts.ts | 16 +++++++++++++--- 5 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..1c62d264 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Edge", + "request": "launch", + "type": "pwa-msedge", + "url": "http://localhost:3000", + "webRoot": "${workspaceFolder}/frontend" + }, + { + "name": "Attach to Edge", + "port": 9222, + "request": "attach", + "type": "pwa-msedge", + "webRoot": "${workspaceFolder}/frontend" + } + + ] +} \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index fdfc4a5e..8666cc69 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "1.0.0-beta.3", + "version": "1.0.0-beta.4", "private": true, "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.34", diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 13f35d50..c5c8e53f 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -9,6 +9,7 @@ import Cookies from "js-cookie"; import { COOKIE_SCHOOL_PREFERENCE } from "./utils/constants"; import { KECHBEvents, KECHGEvents } from "./data/events-mock"; import Footer from "./components/Footer"; +import { KECHBAlerts, KECHGAlerts } from "./data/alerts"; /*function App() { return ( @@ -79,6 +80,9 @@ class App extends Component> { eventsFetcher={ async () => KECHBEvents } + alertsFetcher={ + async () => KECHBAlerts + } /> ), }, @@ -91,6 +95,10 @@ class App extends Component> { eventsFetcher={ async () => KECHGEvents } + + alertsFetcher={ + async () => KECHGAlerts + } /> ), }, diff --git a/frontend/src/components/SiteContainer.tsx b/frontend/src/components/SiteContainer.tsx index df5b0b7b..c6ba14c2 100644 --- a/frontend/src/components/SiteContainer.tsx +++ b/frontend/src/components/SiteContainer.tsx @@ -20,6 +20,8 @@ export interface SiteProps { weekMarkerDate: GregorianDay; /** Events data - eventually replaced with state */ eventsFetcher: () => Promise; + /** Fetches site alert */ + alertsFetcher: () => Promise; } const baseEventImageStyle = { @@ -100,7 +102,8 @@ export default class SiteContainer extends Component { // const response: AlertResponce = await baseResponse.json(); - const response = KECHBAlerts; + //const response = KECHBAlerts; + const response = await this.props.alertsFetcher(); this.setState({ alert: response, @@ -146,6 +149,10 @@ export default class SiteContainer extends Component { forwardOrRewindToDay(d: Date, goTo: GregorianDay, forwardList: number[]) { const dhere = new Date(d); const day = dhere.getUTCDay(); + //console.log(day); + //console.log(dhere.getUTCDate()); + //console.log(forwardList); + //console.log(goTo); // Sunday is day 0 // Sat is Day 6 // If Sun or Sat go to next week @@ -167,12 +174,10 @@ export default class SiteContainer extends Component { async getCalendar() { const inputDate = new Date(); // Used for fiddling: - // inputDate.setDate(1); - // inputDate.setMonth(0); - // inputDate.setFullYear(2021); - - // THis is where we get the date in the calendar to look for (i.e. go back to the last or next Monday) - const weekStart = this.forwardOrRewindToDay(inputDate, this.props.weekMarkerDate, [0, 6]); + //inputDate.setDate(1); + //inputDate.setMonth(2); + //inputDate.setFullYear(2021); + const weekStart = this.forwardOrRewindToDay(inputDate, this.props.weekMarkerDate, [6]); weekStart.setUTCHours(0, 0, 0, 0); // Set to start of day const weekEnd = new Date(weekStart); weekEnd.setUTCDate(weekEnd.getUTCDate() + 1); @@ -263,6 +268,7 @@ export default class SiteContainer extends Component { // NOTE: getScrollDownWithAdditional was originally fed 150 instead of 0 return ( <> + {this.state.alert.showAlert ? : null}

It is neither Week A nor B.

This means it's probably a holiday.

diff --git a/frontend/src/data/alerts.ts b/frontend/src/data/alerts.ts index 4a9cf9bc..c81736da 100644 --- a/frontend/src/data/alerts.ts +++ b/frontend/src/data/alerts.ts @@ -12,8 +12,18 @@ export const KECHBAlerts: AlertResponce = { showAlert: true, //message: "BREAKING: Student Council Chair Adeen Irfan has resigned, triggering an election.", // alertLevel: ThreatLevels.CRITICAL, - message: "NEWS: KECHB team \"The Standard Solutions\" wins the Cambridge Chemistry Race, beating 48 other schools from across the country", + message: "Lateral Flow Testing: Please keep an eye on your parent/guardian's emails. You should have been already been sent some information.", + alertLevel: ThreatLevels.SEVERE, + //linkText: "more info", + //linkTo: "https://twitter.com/KEVICHB/status/1359153991104557064?s=20" +}; + +export const KECHGAlerts: AlertResponce = { + showAlert: false, + //message: "BREAKING: Student Council Chair Adeen Irfan has resigned, triggering an election.", + // alertLevel: ThreatLevels.CRITICAL, + message: "Welcome to IsItWeekA! We'll use these banner for important alerts in the future.", alertLevel: ThreatLevels.LOW, - linkText: "more info", - linkTo: "https://twitter.com/KEVICHB/status/1359153991104557064?s=20" + //linkText: "more info", + //linkTo: "https://twitter.com/KEVICHB/status/1359153991104557064?s=20" };