Skip to content

Commit b71f144

Browse files
committed
Don't show empty table or chart if there are no weight entries
1 parent 5b88e9f commit b71f144

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/components/BodyWeight/Table/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
Paper,
32
Table,
43
TableBody,
54
TableCell,
@@ -54,7 +53,7 @@ export const WeightTable = ({ weights }: WeightTableProps) => {
5453

5554
return (
5655
<div className={classes.table}>
57-
<TableContainer component={Paper}>
56+
<TableContainer>
5857
<Table sx={{ minWidth: 650 }} aria-label="simple table">
5958
<TableHead>
6059
<TableRow>
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
1-
import { Box, Stack, Button, ButtonGroup } from "@mui/material";
1+
import { Box, Stack } from "@mui/material";
22
import { useBodyWeightQuery } from "components/BodyWeight/queries";
33
import { WeightTable } from "components/BodyWeight/Table";
44
import { WeightChart } from "components/BodyWeight/WeightChart";
55
import { AddBodyWeightEntryFab } from "components/BodyWeight/widgets/fab";
6+
import { FilterButtons, FilterType } from "components/BodyWeight/widgets/FilterButtons";
67
import { LoadingPlaceholder } from "components/Core/LoadingWidget/LoadingWidget";
78
import { WgerContainerRightSidebar } from "components/Core/Widgets/Container";
89
import { OverviewEmpty } from "components/Core/Widgets/OverviewEmpty";
9-
import { useTranslation } from "react-i18next";
10-
import { FilterButtons, FilterType } from "components/BodyWeight/widgets/FilterButtons";
1110
import { useState } from "react";
11+
import { useTranslation } from "react-i18next";
1212

1313

1414
export const BodyWeight = () => {
1515
const [t] = useTranslation();
16-
const [filter, setFilter] = useState<FilterType>('lastYear');
16+
const [filter, setFilter] = useState<FilterType>('lastYear');
1717
const weightyQuery = useBodyWeightQuery(filter);
1818
const handleFilterChange = (newFilter: FilterType) => {
1919
setFilter(newFilter);
2020
};
2121

22-
return weightyQuery.isLoading
23-
? <LoadingPlaceholder />
24-
: <WgerContainerRightSidebar
25-
title={t("weight")}
26-
mainContent={<Stack spacing={2}>
22+
if (weightyQuery.isLoading) {
23+
return <LoadingPlaceholder />;
24+
}
25+
26+
return <WgerContainerRightSidebar
27+
title={t("weight")}
28+
mainContent={<Stack spacing={2}>
2729
<FilterButtons currentFilter={filter} onFilterChange={handleFilterChange} />
28-
{weightyQuery.data!.length === 0 && <OverviewEmpty />}
30+
{weightyQuery.data!.length === 0 && <OverviewEmpty />}
31+
{weightyQuery.data!.length !== 0 && <>
2932
<WeightChart weights={weightyQuery.data!} />
3033
<Box sx={{ mt: 4 }} />
3134
<WeightTable weights={weightyQuery.data!} />
32-
</Stack>
33-
}
34-
fab={<AddBodyWeightEntryFab />}
35-
/>;
35+
</>}
36+
</Stack>
37+
}
38+
fab={<AddBodyWeightEntryFab />}
39+
/>;
3640
};

src/components/BodyWeight/widgets/FilterButtons.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,39 @@ export const FilterButtons = ({ currentFilter, onFilterChange }: FilterButtonsPr
2828
onClick={() => handleFilterChange('')}
2929
color={currentFilter === '' ? 'primary' : 'inherit'}
3030
variant={currentFilter === '' ? 'contained' : 'outlined'}
31-
sx={{ fontFamily: theme.typography.fontFamily }}
31+
sx={{ fontFamily: theme.typography.fontFamily }}
3232
>
3333
{t('all')}
3434
</Button>
3535
<Button
3636
onClick={() => handleFilterChange('lastYear')}
3737
color={currentFilter === 'lastYear' ? 'primary' : 'inherit'}
3838
variant={currentFilter === 'lastYear' ? 'contained' : 'outlined'}
39-
sx={{ fontFamily: theme.typography.fontFamily }}
39+
sx={{ fontFamily: theme.typography.fontFamily }}
4040
>
4141
{t('lastYear')}
4242
</Button>
4343
<Button
4444
onClick={() => handleFilterChange('lastHalfYear')}
4545
color={currentFilter === 'lastHalfYear' ? 'primary' : 'inherit'}
4646
variant={currentFilter === 'lastHalfYear' ? 'contained' : 'outlined'}
47-
sx={{ fontFamily: theme.typography.fontFamily }}
47+
sx={{ fontFamily: theme.typography.fontFamily }}
4848
>
4949
{t('lastHalfYear')}
5050
</Button>
5151
<Button
5252
onClick={() => handleFilterChange('lastMonth')}
5353
color={currentFilter === 'lastMonth' ? 'primary' : 'inherit'}
5454
variant={currentFilter === 'lastMonth' ? 'contained' : 'outlined'}
55-
sx={{ fontFamily: theme.typography.fontFamily }}
55+
sx={{ fontFamily: theme.typography.fontFamily }}
5656
>
5757
{t('lastMonth')}
5858
</Button>
5959
<Button
6060
onClick={() => handleFilterChange('lastWeek')}
6161
color={currentFilter === 'lastWeek' ? 'primary' : 'inherit'}
6262
variant={currentFilter === 'lastWeek' ? 'contained' : 'outlined'}
63-
sx={{ fontFamily: theme.typography.fontFamily }}
63+
sx={{ fontFamily: theme.typography.fontFamily }}
6464
>
6565
{t('lastWeek')}
6666
</Button>

0 commit comments

Comments
 (0)