-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: removed nested meals component
- Loading branch information
Showing
4 changed files
with
50 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
import { useMemo, type FC } from 'react'; | ||
import { type NoteItem, getMealTypes, groupNotesByMealType } from '../models'; | ||
import { MealsListItem } from './MealsListItem'; | ||
import { List, ListItem, ListSubheader, Stack, Typography } from '@mui/material'; | ||
import { type FC, useMemo, type PropsWithChildren } from 'react'; | ||
import { getMealName, type NoteItem, type MealType } from '../models'; | ||
import { NotesList } from './NotesList'; | ||
|
||
interface Props { | ||
interface Props extends PropsWithChildren { | ||
mealType: MealType; | ||
notes: NoteItem[]; | ||
} | ||
|
||
export const MealsList: FC<Props> = ({ notes }) => { | ||
const notesGroupedByMealType = useMemo(() => groupNotesByMealType(notes), [notes]); | ||
export const MealsList: FC<Props> = ({ mealType, notes }: Props) => { | ||
const mealName = useMemo(() => getMealName(mealType), [mealType]); | ||
const totalCalories = useMemo(() => notes.reduce((sum, note) => sum + note.calories, 0), [notes]); | ||
|
||
return ( | ||
<> | ||
{getMealTypes().map(mealType => ( | ||
<MealsListItem | ||
key={mealType} | ||
mealType={mealType} | ||
notes={notesGroupedByMealType.get(mealType) ?? []} | ||
/> | ||
))} | ||
</> | ||
<List | ||
subheader={ | ||
<ListSubheader disableGutters> | ||
<Stack direction="row" spacing={1} justifyContent="space-between"> | ||
<Typography fontSize="inherit" fontWeight="inherit" component="span" noWrap> | ||
{mealName} | ||
</Typography> | ||
<Typography | ||
fontSize="inherit" | ||
fontWeight="inherit" | ||
component="span" | ||
width={100} | ||
align="right" | ||
> | ||
{totalCalories} kcal | ||
</Typography> | ||
</Stack> | ||
</ListSubheader> | ||
} | ||
> | ||
<ListItem disableGutters> | ||
<NotesList notes={notes} /> | ||
</ListItem> | ||
</List> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './MealsList'; | ||
export * from './NotesTable'; | ||
export * from './MealsList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters