Skip to content

Commit

Permalink
Show weather station info in Date Range modal.
Browse files Browse the repository at this point in the history
  • Loading branch information
lublagg committed Jan 26, 2024
1 parent 9e3004b commit fc114da
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/components/date-range/calendars.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect, useState } from "react";
import "./calendars.scss";
import { Calendar } from "./calendar";
import { useStateContext } from "../../hooks/use-state";
Expand All @@ -10,8 +10,22 @@ interface ICalendarsProps {
}

export const Calendars = ({selectedCalendar, handleSelectCalendar, closeCalendars}: ICalendarsProps) => {
const {state} = useStateContext();
const {weatherStation} = state;
const { state } = useStateContext();
const { weatherStation } = state;
const [activeDates, setActiveDates] = useState<{from: string, to: string}>({from: "", to: ""});

useEffect(() => {
if (weatherStation) {
const {mindate, maxdate} = weatherStation; //"1973-01-01"
const formatDate = (date: string) => {
const [year, month, day] = date.split("-");
return `${month}/${day}/${year}`;
};
const from = formatDate(mindate);
const to = maxdate === "present" ? "present" : formatDate(maxdate);
setActiveDates({from, to});
}
}, [weatherStation]);

return (
<div className="modal">
Expand All @@ -24,12 +38,16 @@ export const Calendars = ({selectedCalendar, handleSelectCalendar, closeCalendar
</div>
</div>
<div className="calendar-footer">
<div className="station-information">
<div className="station-name">{weatherStation?.name || "WEATHER STATION"}</div>
<div className="station-dates">
<span>MM/DD/YYYY</span> - <span>MM/DD/YYYY</span>
<div className="station-information">
{ weatherStation &&
<>
<div className="station-name">{weatherStation?.name || "WEATHER STATION"}</div>
<div className="station-dates">
<span>{activeDates.from}</span> - <span>{activeDates.to}</span>
</div>
</>
}
</div>
</div>
<button className="close-calendar" onClick={closeCalendars}>Done</button>
</div>
</div>
Expand Down

0 comments on commit fc114da

Please sign in to comment.