diff --git a/src/components/date-range/calendars.tsx b/src/components/date-range/calendars.tsx index 2813d65..fda7f89 100644 --- a/src/components/date-range/calendars.tsx +++ b/src/components/date-range/calendars.tsx @@ -1,8 +1,9 @@ -import React from "react"; -import "./calendars.scss"; +import React, { useEffect, useState } from "react"; import { Calendar } from "./calendar"; import { useStateContext } from "../../hooks/use-state"; +import "./calendars.scss"; + interface ICalendarsProps { selectedCalendar: string | undefined; handleSelectCalendar: (calendar: string) => void; @@ -10,8 +11,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 +39,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} +
+ + }
-