|
@@ -3,7 +3,6 @@ import ReactSwipe from 'react-swipe';
|
|
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';
|
|
-import { ItemActions } from './ItemActions';
|
|
|
|
import { ItemList } from './ItemList';
|
|
import { ItemList } from './ItemList';
|
|
import { ListEditBox } from './ListEditBox';
|
|
import { ListEditBox } from './ListEditBox';
|
|
import styles from './caloriesList.css';
|
|
import styles from './caloriesList.css';
|
|
@@ -30,11 +29,6 @@ function CaloriesList () {
|
|
setCalorieItems(updatedCalories);
|
|
setCalorieItems(updatedCalories);
|
|
}
|
|
}
|
|
|
|
|
|
- function removeItem () {
|
|
|
|
- setCalorieItems(calorieItems.filter((item) => item !== selectedItem));
|
|
|
|
- setSelectedItem();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
function saveCalories (changedCalories: { title: string, count: number }) {
|
|
function saveCalories (changedCalories: { title: string, count: number }) {
|
|
if (!selectedItem) {
|
|
if (!selectedItem) {
|
|
return;
|
|
return;
|
|
@@ -56,6 +50,11 @@ function CaloriesList () {
|
|
setSelectedItem(updatedItem);
|
|
setSelectedItem(updatedItem);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function removeItem (itemToRemove: CalorieValue) {
|
|
|
|
+ setCalorieItems(calorieItems.filter((item) => item !== selectedItem));
|
|
|
|
+ setSelectedItem();
|
|
|
|
+ }
|
|
|
|
+
|
|
function onRowClick (item: CalorieValue) {
|
|
function onRowClick (item: CalorieValue) {
|
|
if (selectedItem === item) {
|
|
if (selectedItem === item) {
|
|
return setSelectedItem(undefined);
|
|
return setSelectedItem(undefined);
|
|
@@ -103,20 +102,14 @@ function CaloriesList () {
|
|
}}>
|
|
}}>
|
|
{dayCalories.map(({date, items}) => {
|
|
{dayCalories.map(({date, items}) => {
|
|
return (
|
|
return (
|
|
- <ItemList key={date} {...{items, selectedItem, onRowClick, onClick: () => setSelectedItem() }} />
|
|
|
|
|
|
+ <ItemList key={date} {...{items, selectedItem, onRowClick, onClick: () => setSelectedItem(), removeItem }} />
|
|
);
|
|
);
|
|
})}
|
|
})}
|
|
</ReactSwipe>
|
|
</ReactSwipe>
|
|
|
|
|
|
<div className={styles.editBoxes}>
|
|
<div className={styles.editBoxes}>
|
|
- {selectedItem &&
|
|
|
|
- <ListEditBox>
|
|
|
|
- <ItemActions {...{removeItem}} />
|
|
|
|
- </ListEditBox>
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
<ListEditBox>
|
|
<ListEditBox>
|
|
- <CaloriesInput {...{addCalories, saveCalories, item: selectedItem}} />
|
|
|
|
|
|
+ <CaloriesInput {...{addCalories, saveCalories, item: selectedItem }} />
|
|
</ListEditBox>
|
|
</ListEditBox>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</section>
|