Skip to content

Commit cecf169

Browse files
committed
[front-end] Add ApplyFilters component and integrate filter application in Panel
1 parent a2a9471 commit cecf169

File tree

3 files changed

+70
-34
lines changed

3 files changed

+70
-34
lines changed

apps/front-end/src/components/panel/Panel.tsx

+25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CloseButton from "../common/closeButton/CloseButton";
88
import AboutPanel from "./aboutPanel/AboutPanel";
99
import DirectoryPanel from "./directoryPanel/DirectoryPanel";
1010
import SearchPanel from "./searchPanel/SearchPanel";
11+
import ApplyFilters from "./applyFilters/ApplyFilters";
1112
import ResultsPanel from "../panel/resultsPanel/ResultsPanel";
1213
import { useAppDispatch, useAppSelector } from "../../app/hooks";
1314
import {
@@ -18,7 +19,14 @@ import {
1819
selectPanelOpen,
1920
selectResultsPanelOpen,
2021
openPanel,
22+
openResultsPanel,
2123
} from "./panelSlice";
24+
import {
25+
selectText,
26+
performSearch,
27+
selectIsFilterActive,
28+
} from "../panel/searchPanel/searchSlice";
29+
import { useTranslation } from "react-i18next";
2230

2331
const StyledPanel = styled(Drawer)(() => ({
2432
display: "flex",
@@ -36,6 +44,7 @@ const StyledPanel = styled(Drawer)(() => ({
3644
visibility: "visible !important",
3745
overflow: "visible",
3846
boxShadow: "0 0 20px rgba(0, 0, 0, 0.16)",
47+
borderRight: "none",
3948
},
4049
}));
4150

@@ -52,6 +61,9 @@ const Panel = () => {
5261
const isOpen = useAppSelector(selectPanelOpen);
5362
const selectedTab = useAppSelector(selectSelectedTab);
5463
const resultsOpen = useAppSelector(selectResultsPanelOpen);
64+
const isFilterActive = useAppSelector(selectIsFilterActive);
65+
const searchText = useAppSelector(selectText);
66+
const { t } = useTranslation();
5567

5668
const isMedium = useMediaQuery("(min-width: 897px)");
5769

@@ -81,6 +93,12 @@ const Panel = () => {
8193
dispatch(setSelectedTab(0));
8294
};
8395

96+
const onApplyFilters = async () => {
97+
console.log(`Applying filters`);
98+
await dispatch(performSearch());
99+
dispatch(openResultsPanel());
100+
};
101+
84102
return (
85103
<>
86104
{/* Desktop view */}
@@ -137,6 +155,13 @@ const Panel = () => {
137155
boxShadow: "0 -2px 10px rgba(0, 0, 0, 0.2)",
138156
}}
139157
>
158+
{selectedTab === 2 && (
159+
<ApplyFilters
160+
buttonText={t("apply_filters")}
161+
buttonAction={onApplyFilters}
162+
disabled={!searchText && !isFilterActive}
163+
/>
164+
)}
140165
<NavBar
141166
onTabChange={handleTabChange}
142167
selectedTab={selectedTab}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Box from "@mui/material/Box";
2+
import { styled } from "@mui/material/styles";
3+
import StandardButton from "../../common/standardButton/StandardButton";
4+
5+
const StyledButtonContainer = styled(Box)(() => ({
6+
width: "100%",
7+
display: "flex",
8+
justifyContent: "center",
9+
position: "sticky",
10+
padding: "var(--spacing-medium)",
11+
backgroundColor: "#fff",
12+
boxShadow: "0 0 20px rgba(0, 0, 0, 0.16)",
13+
margin: 0,
14+
"@media (min-width: 897px)": {
15+
display: "none",
16+
},
17+
}));
18+
19+
interface ApplyFiltersProps {
20+
buttonText: string;
21+
disabled: boolean;
22+
buttonAction: () => void;
23+
}
24+
25+
const ApplyFilters = ({buttonText, buttonAction, disabled}: ApplyFiltersProps) => {
26+
return (
27+
<StyledButtonContainer>
28+
<StandardButton
29+
buttonAction={buttonAction}
30+
disabled={disabled}
31+
>
32+
{buttonText}
33+
</StandardButton>
34+
</StyledButtonContainer>
35+
);
36+
};
37+
38+
export default ApplyFilters;

apps/front-end/src/components/panel/searchPanel/SearchPanel.tsx

+7-34
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import Heading from "../heading/Heading";
55
import ContentPanel from "../contentPanel/ContentPanel";
66
import SelectBox from "../../common/selectBox/SelectBox";
77
import SearchBox from "./searchBox/SearchBox";
8-
import StandardButton from "../../common/standardButton/StandardButton";
98
import Typography from "@mui/material/Typography";
10-
import Box from "@mui/material/Box";
11-
import { styled } from "@mui/material/styles";
129
import useMediaQuery from "@mui/material/useMediaQuery";
1310
import { useAppDispatch, useAppSelector } from "../../../app/hooks";
1411
import {
@@ -23,20 +20,6 @@ import {
2320
import { selectTotalItemsCount } from "../../map/mapSlice";
2421
import { openResultsPanel } from "../panelSlice";
2522

26-
const StyledButtonContainer = styled(Box)(() => ({
27-
width: "100%",
28-
display: "flex",
29-
justifyContent: "center",
30-
position: "sticky",
31-
padding: "var(--spacing-medium)",
32-
backgroundColor: "rgba(255, 255, 255, 0.25) !important",
33-
boxShadow: "0 0 20px rgba(0, 0, 0, 0.16)",
34-
zIndex: 1,
35-
"@media (min-width: 897px)": {
36-
display: "none",
37-
},
38-
}));
39-
4023
const SearchPanel = () => {
4124
const dispatch = useAppDispatch();
4225
const { t } = useTranslation();
@@ -53,6 +36,7 @@ const SearchPanel = () => {
5336

5437
const onSearchChange = (e: React.FormEvent<HTMLInputElement>): void => {
5538
setCurrentText(e.currentTarget.value);
39+
dispatch(setText(currentText));
5640
};
5741

5842
const onFilterChange = async (
@@ -65,12 +49,6 @@ const SearchPanel = () => {
6549
if (isMedium) dispatch(openResultsPanel());
6650
};
6751

68-
const onApplyFilters = async () => {
69-
console.log(`Applying filters`);
70-
await dispatch(performSearch());
71-
dispatch(openResultsPanel());
72-
};
73-
7452
const onSubmitSearch = async () => {
7553
console.log(`Searching for '${submittedText}'`);
7654
dispatch(setText(currentText));
@@ -87,7 +65,12 @@ const SearchPanel = () => {
8765

8866
return (
8967
<form
90-
style={{ display: "flex", flexDirection: "column", overflow: "hidden" }} // Fix for search filter overflow issue
68+
style={{
69+
display: "flex",
70+
flexDirection: "column",
71+
overflow: "hidden",
72+
paddingBottom: "80px",
73+
}} // Fix for search filter overflow issue
9174
>
9275
<Heading title={t("search")}>
9376
<SearchBox
@@ -113,16 +96,6 @@ const SearchPanel = () => {
11396
/>
11497
))}
11598
</ContentPanel>
116-
<StyledButtonContainer>
117-
{!isMedium && (
118-
<StandardButton
119-
buttonAction={onApplyFilters}
120-
disabled={!currentText && !isFilterActive}
121-
>
122-
{t("apply_filters")}
123-
</StandardButton>
124-
)}
125-
</StyledButtonContainer>
12699
</form>
127100
);
128101
};

0 commit comments

Comments
 (0)