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 (