From fc114da3c3f1d54478e6431d34d2a0c3097521ed Mon Sep 17 00:00:00 2001 From: lublagg Date: Thu, 25 Jan 2024 20:30:06 -0500 Subject: [PATCH] Show weather station info in Date Range modal. --- src/components/date-range/calendars.tsx | 34 +++++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/date-range/calendars.tsx b/src/components/date-range/calendars.tsx index 2813d65..599802a 100644 --- a/src/components/date-range/calendars.tsx +++ b/src/components/date-range/calendars.tsx @@ -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"; @@ -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 (
@@ -24,12 +38,16 @@ export const Calendars = ({selectedCalendar, handleSelectCalendar, closeCalendar
-
-
{weatherStation?.name || "WEATHER STATION"}
-
- MM/DD/YYYY - MM/DD/YYYY +
+ { weatherStation && + <> +
{weatherStation?.name || "WEATHER STATION"}
+
+ {activeDates.from} - {activeDates.to} +
+ + }
-