Skip to content

Commit bb855fa

Browse files
committed
feat: add count of filters to the mobile view
1 parent 99b2ef5 commit bb855fa

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

src/components/InlineFilters/InlineFilters.tsx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import {
1616
} from '@mui/material';
1717
import { useTranslations } from 'next-intl';
1818
import { FC, useState } from 'react';
19-
import { ProductsFilters } from '../ProductsFilters';
2019
import Dialog from '../Dialog/Dialog';
20+
import { ProductsFilters } from '../ProductsFilters';
2121

2222
export interface InlineFiltersProps {}
2323
const InlineFilters: FC<InlineFiltersProps> = () => {
2424
const t = useTranslations();
2525

26-
const { sort, navigate } = useSearchPageParams();
26+
const { sort, navigate, count, clear } = useSearchPageParams();
2727

2828
const [sortDialog, setSortDialog] = useState(false);
2929

@@ -48,6 +48,11 @@ const InlineFilters: FC<InlineFiltersProps> = () => {
4848
setFiltersDialog((prevState) => !prevState);
4949
};
5050

51+
const handleClickOnClear = () => {
52+
clear();
53+
onToggleFiltersDialog();
54+
};
55+
5156
return (
5257
<>
5358
<Dialog
@@ -64,6 +69,24 @@ const InlineFilters: FC<InlineFiltersProps> = () => {
6469
fullWidth: true,
6570
onClick: onToggleFiltersDialog,
6671
},
72+
{
73+
id: 'clear-filters',
74+
children: t('products.filters.buttons.removeFilters'),
75+
...(!!count
76+
? {
77+
color: 'error',
78+
variant: 'outlined',
79+
}
80+
: {
81+
color: 'inherit',
82+
variant: 'contained',
83+
disabled: true,
84+
}),
85+
86+
size: 'large',
87+
fullWidth: true,
88+
onClick: handleClickOnClear,
89+
},
6790
]}
6891
>
6992
<ProductsFilters />
@@ -111,18 +134,41 @@ const InlineFilters: FC<InlineFiltersProps> = () => {
111134
}}
112135
>
113136
<Button
137+
color="inherit"
114138
variant="outlined"
115139
size="small"
116140
endIcon={<SortOutlined />}
117141
onClick={onOpenSortDialog}
118142
>
119143
{t(selectedSort?.label || sortOptions[0].label)}
120144
</Button>
145+
121146
<Button
147+
color="inherit"
122148
variant="outlined"
123149
size="small"
124150
endIcon={<KeyboardArrowDownIcon />}
125151
onClick={onToggleFiltersDialog}
152+
startIcon={
153+
!!count && (
154+
<Box
155+
width={18}
156+
height={18}
157+
sx={{
158+
display: 'flex',
159+
alignItems: 'center',
160+
justifyContent: 'center',
161+
backgroundColor: (theme) => theme.palette.error.main,
162+
borderRadius: '50%',
163+
color: '#fff',
164+
fontSize: (theme) =>
165+
`${theme.typography.caption.fontSize} !important`,
166+
}}
167+
>
168+
{count}
169+
</Box>
170+
)
171+
}
126172
>
127173
{t('products.filters.title')}
128174
</Button>

0 commit comments

Comments
 (0)