Skip to content

Commit

Permalink
Adjust date-range related status message logic
Browse files Browse the repository at this point in the history
- Do not show station active message when no date range is selected
- In cases where user requests data from before a station existed, show station inactive warning
  • Loading branch information
bacalj committed Jul 23, 2024
1 parent a8ca234 commit 72bb2b5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,24 @@ export const App = () => {
const maxDate = endDate || new Date(Date.now());
guaranteeGlobal(globalMinDate, Number(minDate)/1000);
guaranteeGlobal(globalMaxDate, Number(maxDate)/1000);
}, [endDate, startDate, weatherStations]);
if (weatherStation && (!startDate || !endDate)) {
setStatus({
status: "error",
message: "Select a date range",
icon: <WarningIcon/>
});
}
// if the start date of the weather station is after the user's requested end date, then the station is inactive
const stationMinDate = new Date(weatherStation?.mindate || globalMinDate);
const stationNotActiveYet = stationMinDate > maxDate;
if (stationNotActiveYet) {
setStatus({
status: "station-error",
message: "Station was inactive for date range",
icon: <WarningIcon/>
});
}
}, [endDate, startDate, weatherStations, weatherStation]);

const stationSelectionHandler = async(req: any) =>{
if (req.values.operation === "selectCases") {
Expand Down Expand Up @@ -237,7 +254,7 @@ export const App = () => {
setIsFetching(false);
setStatus({
status: "error",
message: "No data retrieved. Try different frequency or station.",
message: "No data retrieved. Change frequency or station.",
icon: <WarningIcon/>
});
}
Expand Down

0 comments on commit 72bb2b5

Please sign in to comment.