|
@@ -9,12 +9,14 @@ import { ListEditBox } from './ListEditBox';
|
|
import styles from './caloriesList.css';
|
|
import styles from './caloriesList.css';
|
|
|
|
|
|
function CaloriesList () {
|
|
function CaloriesList () {
|
|
- const {calorieItems = [], setCalorieItems, selectedDate, setSelectedDate} = useContext(AppContext);
|
|
|
|
- const [selectedItem, setSelectedItem] = useState<CalorieValue>();
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- setSelectedItem(undefined);
|
|
|
|
- }, [selectedDate]);
|
|
|
|
|
|
+ const {
|
|
|
|
+ calorieItems = [],
|
|
|
|
+ setCalorieItems,
|
|
|
|
+ selectedDate,
|
|
|
|
+ setSelectedDate,
|
|
|
|
+ selectedItem,
|
|
|
|
+ setSelectedItem
|
|
|
|
+ } = useContext(AppContext);
|
|
|
|
|
|
function addCalories (addedCalories: { title: string, count: number }) {
|
|
function addCalories (addedCalories: { title: string, count: number }) {
|
|
const updatedCalories = [
|
|
const updatedCalories = [
|
|
@@ -30,6 +32,7 @@ function CaloriesList () {
|
|
|
|
|
|
function removeItem () {
|
|
function removeItem () {
|
|
setCalorieItems(calorieItems.filter((item) => item !== selectedItem));
|
|
setCalorieItems(calorieItems.filter((item) => item !== selectedItem));
|
|
|
|
+ setSelectedItem();
|
|
}
|
|
}
|
|
|
|
|
|
function saveCalories (changedCalories: { title: string, count: number }) {
|
|
function saveCalories (changedCalories: { title: string, count: number }) {
|
|
@@ -61,7 +64,7 @@ function CaloriesList () {
|
|
return setSelectedItem(item);
|
|
return setSelectedItem(item);
|
|
}
|
|
}
|
|
|
|
|
|
- const swipeItem = (date: number, items: CalorieValue[]) => ({ date, items });
|
|
|
|
|
|
+ const swipeItem = (date: number, items: CalorieValue[]) => ({date, items});
|
|
|
|
|
|
const dayCalories = [
|
|
const dayCalories = [
|
|
selectedDate - 3600 * 24 * 1000,
|
|
selectedDate - 3600 * 24 * 1000,
|
|
@@ -98,7 +101,7 @@ function CaloriesList () {
|
|
height: '100%'
|
|
height: '100%'
|
|
}
|
|
}
|
|
}}>
|
|
}}>
|
|
- {dayCalories.map(({ date, items }) => {
|
|
|
|
|
|
+ {dayCalories.map(({date, items}) => {
|
|
return (
|
|
return (
|
|
<ItemList key={date} {...{items, selectedItem, onRowClick}} />
|
|
<ItemList key={date} {...{items, selectedItem, onRowClick}} />
|
|
);
|
|
);
|