|
@@ -1,4 +1,4 @@
|
|
-import React, { useContext, useState } from 'react';
|
|
|
|
|
|
+import React, { useContext, useEffect, useState } from 'react';
|
|
import { AppContext } from '../../layout/AppContext';
|
|
import { AppContext } from '../../layout/AppContext';
|
|
import { haveSameDay } from '../../utils/date';
|
|
import { haveSameDay } from '../../utils/date';
|
|
import { CaloriesInput } from '../caloriesInput/CaloriesInput';
|
|
import { CaloriesInput } from '../caloriesInput/CaloriesInput';
|
|
@@ -11,6 +11,10 @@ function CaloriesList () {
|
|
const {calorieItems = [], setCalorieItems, selectedDate} = useContext(AppContext);
|
|
const {calorieItems = [], setCalorieItems, selectedDate} = useContext(AppContext);
|
|
const [selectedItem, setSelectedItem] = useState<CalorieValue>();
|
|
const [selectedItem, setSelectedItem] = useState<CalorieValue>();
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ setSelectedItem(undefined);
|
|
|
|
+ }, [selectedDate]);
|
|
|
|
+
|
|
function addCalories (addedCalories: { title: string, count: number }) {
|
|
function addCalories (addedCalories: { title: string, count: number }) {
|
|
const updatedCalories = [
|
|
const updatedCalories = [
|
|
...calorieItems,
|
|
...calorieItems,
|