Skip to content

Commit

Permalink
Show list items in two columns on large screens
Browse files Browse the repository at this point in the history
  • Loading branch information
pkirilin committed Mar 20, 2024
1 parent 9bc3d25 commit ea1b54d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
24 changes: 15 additions & 9 deletions src/frontend/src/features/notes/ui/NotesList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { List, ListSubheader, Stack, Typography } from '@mui/material';
import { Grid, List, ListItem, ListSubheader, Stack, Typography } from '@mui/material';
import { useMemo, type FC } from 'react';
import { getMealName, type MealType, type NoteItem } from '../models';
import { AddNote } from './AddNote';
Expand Down Expand Up @@ -52,14 +52,20 @@ export const NotesList: FC<Props> = ({ pageId, mealType, notes }) => {
}
sx={{ width: '100%' }}
>
{notes.map(note => (
<NotesListItem key={note.id} note={note} pageId={pageId} />
))}
<AddNote
pageId={pageId}
mealType={mealType}
displayOrder={maxDisplayOrderForNotesGroup + 1}
/>
<ListItem disableGutters disablePadding>
<Grid container columnSpacing={4} component={List} disablePadding>
{notes.map(note => (
<NotesListItem key={note.id} note={note} pageId={pageId} />
))}
</Grid>
</ListItem>
<ListItem>
<AddNote
pageId={pageId}
mealType={mealType}
displayOrder={maxDisplayOrderForNotesGroup + 1}
/>
</ListItem>
</List>
);
};
62 changes: 32 additions & 30 deletions src/frontend/src/features/notes/ui/NotesListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DeleteIcon from '@mui/icons-material/Delete';
import { ListItem, IconButton, ListItemButton, ListItemText, Tooltip } from '@mui/material';
import { ListItem, IconButton, ListItemButton, ListItemText, Tooltip, Grid } from '@mui/material';
import { type FC } from 'react';
import { type NoteItem } from '../models';
import { DeleteNote } from './DeleteNote';
Expand All @@ -10,33 +10,35 @@ interface Props {
pageId: number;
}

export const NotesListItem: FC<Props> = ({ note, pageId }) => {
return (
<ListItem
disablePadding
key={note.id}
secondaryAction={
<DeleteNote note={note} pageId={pageId}>
{toggleDeleteDialog => (
<Tooltip title="Delete note">
<IconButton edge="end" onClick={toggleDeleteDialog}>
<DeleteIcon />
</IconButton>
</Tooltip>
)}
</DeleteNote>
}
>
<EditNote note={note} pageId={pageId}>
{toggleEditDialog => (
<ListItemButton onClick={toggleEditDialog}>
<ListItemText
primary={note.productName}
secondary={`${note.productQuantity} g, ${note.calories} kcal`}
/>
</ListItemButton>
export const NotesListItem: FC<Props> = ({ note, pageId }) => (
<Grid
key={note.id}
item
xs={12}
md={6}
component={ListItem}
disablePadding
secondaryAction={
<DeleteNote note={note} pageId={pageId}>
{toggleDeleteDialog => (
<Tooltip title="Delete note">
<IconButton edge="end" onClick={toggleDeleteDialog}>
<DeleteIcon />
</IconButton>
</Tooltip>
)}
</EditNote>
</ListItem>
);
};
</DeleteNote>
}
>
<EditNote note={note} pageId={pageId}>
{toggleEditDialog => (
<ListItemButton onClick={toggleEditDialog}>
<ListItemText
primary={note.productName}
secondary={`${note.productQuantity} g, ${note.calories} kcal`}
/>
</ListItemButton>
)}
</EditNote>
</Grid>
);

0 comments on commit ea1b54d

Please sign in to comment.