Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show weather station info in Date Range picker (PT-186862140) #29

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading