Use date from option
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { LineChart, Line, CartesianGrid, XAxis, YAxis } from "recharts";
|
||||
import { format, addDays } from "date-fns";
|
||||
import { format, addDays, getUnixDays } from "date-fns";
|
||||
import {
|
||||
formatDate,
|
||||
minDate,
|
||||
@@ -52,9 +52,14 @@ const WeatherChart = function ({ data }) {
|
||||
};
|
||||
|
||||
export const Dashboard = function ({ state, updateState }) {
|
||||
const [dateTime, setDateTime] = useState(
|
||||
minDate(state?.options?.startDate || new Date()),
|
||||
);
|
||||
const defaultDate = path(["options", "defaultDate"], state);
|
||||
const minimumDate = minDate(new Date());
|
||||
|
||||
// Make sure the default date entered by the user is bigger than the minimum date that the API allows.
|
||||
const initialDate =
|
||||
defaultDate && defaultDate > minimumDate ? defaultDate : minimumDate;
|
||||
|
||||
const [dateTime, setDateTime] = useState(initialDate);
|
||||
|
||||
const dateKey = formatDate(dateTime);
|
||||
const data = path(["dataCache", dateKey], state);
|
||||
|
||||
@@ -28,6 +28,7 @@ export const ForecastDatePicker = function ({
|
||||
Forecast date (min. of 14 days in advance) <br />
|
||||
<input
|
||||
type="date"
|
||||
defaultValue={formatDate(minDate(new Date()))}
|
||||
value={formatDate(dateTime)}
|
||||
min={formatDate(minDate(new Date()))}
|
||||
max={formatDate(maxDate(new Date()))}
|
||||
|
||||
Reference in New Issue
Block a user