|
| 1 | +import KeywordFilter from "./KeywordFilter"; |
| 2 | +import ModalitiesFilter from "./ModalitiesFilter"; |
| 3 | +import FilterListIcon from "@mui/icons-material/FilterList"; |
| 4 | +import { |
| 5 | + IconButton, |
| 6 | + Menu, |
| 7 | + MenuItem, |
| 8 | + Box, |
| 9 | + Typography, |
| 10 | + Divider, |
| 11 | +} from "@mui/material"; |
| 12 | +import { Colors } from "design/theme"; |
| 13 | +import React, { useState, useEffect } from "react"; |
| 14 | + |
| 15 | +interface FilterMenuProps { |
| 16 | + onKeywordFilter: (query: string) => void; |
| 17 | + onModalitiesFilter: (selectedModalities: string[]) => void; |
| 18 | + filterKeyword: string; // receive from parent |
| 19 | + homeSelectedModalities: string[]; // receive from parent |
| 20 | +} |
| 21 | + |
| 22 | +const FilterMenu: React.FC<FilterMenuProps> = ({ |
| 23 | + onKeywordFilter, |
| 24 | + onModalitiesFilter, |
| 25 | + filterKeyword, //receive from home parent |
| 26 | + homeSelectedModalities, // receive from parent |
| 27 | +}) => { |
| 28 | + const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); |
| 29 | + // const [filterType, setFilterType] = useState<string | null>(null); |
| 30 | + const [menuKey, setMenuKey] = useState(0); // Forces re-render |
| 31 | + |
| 32 | + useEffect(() => { |
| 33 | + const handleResize = () => { |
| 34 | + setMenuKey((prevKey) => prevKey + 1); |
| 35 | + }; |
| 36 | + |
| 37 | + window.addEventListener("resize", handleResize); |
| 38 | + return () => window.removeEventListener("resize", handleResize); |
| 39 | + }, []); |
| 40 | + |
| 41 | + // Handle menu open and close |
| 42 | + const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { |
| 43 | + setAnchorEl(event.currentTarget); |
| 44 | + }; |
| 45 | + |
| 46 | + const handleClose = () => { |
| 47 | + setAnchorEl(null); |
| 48 | + // setFilterType(null); //reset menu state when closing |
| 49 | + }; |
| 50 | + |
| 51 | + return ( |
| 52 | + <Box> |
| 53 | + {/* Filter Icon Button */} |
| 54 | + <IconButton |
| 55 | + onClick={handleClick} |
| 56 | + sx={{ |
| 57 | + color: Colors.lightGray, |
| 58 | + "&:hover": { |
| 59 | + color: Colors.green, |
| 60 | + backgroundColor: Colors.darkPurple, |
| 61 | + boxShadow: `0px 0px 15px ${Colors.darkGreen}`, |
| 62 | + padding: "10px", |
| 63 | + }, |
| 64 | + }} |
| 65 | + > |
| 66 | + <FilterListIcon /> |
| 67 | + {/* <Typography |
| 68 | + sx={{ |
| 69 | + color: Colors.lightGray, |
| 70 | + fontWeight: "bold", |
| 71 | + }} |
| 72 | + > |
| 73 | + Databases Filter |
| 74 | + </Typography> */} |
| 75 | + </IconButton> |
| 76 | + |
| 77 | + {/* Dropdown Menu */} |
| 78 | + <Menu |
| 79 | + anchorEl={anchorEl} |
| 80 | + open={Boolean(anchorEl)} |
| 81 | + onClose={handleClose} |
| 82 | + disablePortal // Ensures positioning inside the DOM |
| 83 | + sx={{ |
| 84 | + transition: "transform 0.3s ease, opacity 0.3s ease", |
| 85 | + transformOrigin: "top right", |
| 86 | + "& .MuiPaper-root": { |
| 87 | + // backgroundColor: "rgba(40, 44, 86, 0.1)", // Override Paper's default background |
| 88 | + backgroundColor: Colors.lightGray, |
| 89 | + // boxShadow: `0px 0px 5px ${Colors.lightGray}`, |
| 90 | + backdropFilter: "blur(15px)", |
| 91 | + }, |
| 92 | + }} |
| 93 | + > |
| 94 | + {/* unified panel */} |
| 95 | + <Box |
| 96 | + sx={{ |
| 97 | + // backgroundColor: Colors.darkPurple, |
| 98 | + // backdropFilter: "blur(15px)", |
| 99 | + minWidth: 300, |
| 100 | + padding: "10px", |
| 101 | + }} |
| 102 | + > |
| 103 | + <Typography |
| 104 | + sx={{ |
| 105 | + fontSize: "x-large", |
| 106 | + fontWeight: "bold", |
| 107 | + color: Colors.orange, |
| 108 | + }} |
| 109 | + > |
| 110 | + Databases Filter |
| 111 | + </Typography> |
| 112 | + |
| 113 | + <Divider |
| 114 | + sx={{ |
| 115 | + marginY: 2, |
| 116 | + // borderColor: Colors.darkPurple, |
| 117 | + }} |
| 118 | + /> |
| 119 | + |
| 120 | + {/* Keyword Filter */} |
| 121 | + <Box |
| 122 | + sx={{ |
| 123 | + display: "flex", |
| 124 | + flexDirection: "column", |
| 125 | + gap: "2px", |
| 126 | + }} |
| 127 | + > |
| 128 | + <Typography |
| 129 | + variant="subtitle1" |
| 130 | + sx={{ color: Colors.darkGreen, fontWeight: "bold" }} |
| 131 | + > |
| 132 | + Filter by Keyword |
| 133 | + </Typography> |
| 134 | + <KeywordFilter |
| 135 | + onFilter={onKeywordFilter} |
| 136 | + filterKeyword={filterKeyword} |
| 137 | + /> |
| 138 | + </Box> |
| 139 | + |
| 140 | + <Divider |
| 141 | + sx={{ |
| 142 | + marginY: 2, |
| 143 | + // borderColor: Colors.lightGray |
| 144 | + }} |
| 145 | + /> |
| 146 | + |
| 147 | + {/* Modalities Filter */} |
| 148 | + <Box |
| 149 | + sx={{ |
| 150 | + display: "flex", |
| 151 | + flexDirection: "column", |
| 152 | + gap: "2px", |
| 153 | + }} |
| 154 | + > |
| 155 | + <Typography |
| 156 | + variant="subtitle1" |
| 157 | + sx={{ color: Colors.darkGreen, fontWeight: "bold" }} |
| 158 | + > |
| 159 | + Filter by Modalities |
| 160 | + </Typography> |
| 161 | + <ModalitiesFilter |
| 162 | + onFilter={onModalitiesFilter} |
| 163 | + homeSeletedModalities={homeSelectedModalities} |
| 164 | + /> |
| 165 | + </Box> |
| 166 | + </Box> |
| 167 | + </Menu> |
| 168 | + </Box> |
| 169 | + ); |
| 170 | +}; |
| 171 | + |
| 172 | +export default FilterMenu; |
0 commit comments