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