Warning Header (Closes #205) #394

Merged
snedadah merged 19 commits from warning-header into main 2022-02-22 23:29:55 -05:00
1 changed files with 10 additions and 9 deletions
Showing only changes of commit 936d7547f9 - Show all commits

View File

@ -25,35 +25,36 @@ function getCurrentWarning(): Warning | null {
isNaN(startDate.getTime()) || // this checks if the parsed date is not valid (eg. wrong format), since getLocalDateFromEST fails with invalid dates
isNaN(endDate.getTime())
) {
// this warning is not valid, dont try to call getLocalDateFromEST
throw new Error('WARNING WITH INVALID DATES: "' + warning.message + '"');
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.
}
startDate = getLocalDateFromEST(startDate);
endDate = getLocalDateFromEST(endDate);
// check if current warning is in range
return (
startDate.getTime() < today.getTime() &&
endDate.getTime() > today.getTime()
startDate.getTime() <= today.getTime() &&
endDate.getTime() >= today.getTime()
);
});
if (currentWarnings.length > 1) {
// we should not throw here, since this could happen a date far after the push was made, and no one would know they site is down unless someone visits
// If more than one warning is scheduled, log an error to the console. We cannot throw an error, since the site would go down on the live
// website, on the day when more than one warning is scheduled.
console.error(
"ERROR: MORE THAN ONE WARNING SCHEDULED CURRENTLY! ",
currentWarnings
);
}
return currentWarnings.length == 0 ? null : currentWarnings[0];
return currentWarnings.length === 0 ? null : currentWarnings[0];
}
export function WarningHeader() {
const warning = getCurrentWarning();
return warning == null ? null : (
<div className={styles.warning}>{warning.message}</div>
);
if (warning == null) {
return null;
}
return <div className={styles.warning}>{warning.message}</div>;
}