|
@@ -1,4 +1,4 @@
|
|
-import React, { ChangeEvent, useContext } from 'react';
|
|
|
|
|
|
+import React, { ChangeEvent, useContext, useEffect } from 'react';
|
|
import { AppContext } from '../../layout/AppContext';
|
|
import { AppContext } from '../../layout/AppContext';
|
|
import { getDateString } from '../../utils/date';
|
|
import { getDateString } from '../../utils/date';
|
|
import styles from './caloriesDateInput.css';
|
|
import styles from './caloriesDateInput.css';
|
|
@@ -6,10 +6,13 @@ import styles from './caloriesDateInput.css';
|
|
function CaloriesDateInput () {
|
|
function CaloriesDateInput () {
|
|
const {selectedDate, setSelectedDate, setSelectedItem} = useContext(AppContext);
|
|
const {selectedDate, setSelectedDate, setSelectedItem} = useContext(AppContext);
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ setSelectedItem();
|
|
|
|
+ }, [selectedDate]);
|
|
|
|
+
|
|
function onDateChange (event: ChangeEvent<HTMLInputElement>) {
|
|
function onDateChange (event: ChangeEvent<HTMLInputElement>) {
|
|
const newDate = (new Date(event.target.value)).getTime();
|
|
const newDate = (new Date(event.target.value)).getTime();
|
|
setSelectedDate(newDate);
|
|
setSelectedDate(newDate);
|
|
- setSelectedItem();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
const date = new Date(selectedDate);
|
|
const date = new Date(selectedDate);
|