11import {
2- Box ,
3- FormControl ,
4- InputLabel ,
5- Select ,
6- MenuItem ,
72 Stack ,
83 Checkbox ,
9- ListItemText ,
10- OutlinedInput ,
4+ FormControlLabel ,
5+ Typography ,
116} from "@mui/material" ;
127import { DebouncedSearchInput } from "@/components/shared/DebouncedSearchInput" ;
138import { useState , useEffect , useMemo } from "react" ;
@@ -44,12 +39,14 @@ const MenuProps = {
4439 */
4540export const MapFilter = ( { maps, onFilterChange } ) => {
4641 const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
47- const [ selectedModes , setSelectedModes ] = useState ( [ ] ) ;
42+ const [ selectedModes , setSelectedModes ] = useState ( [ "warfare" ] ) ;
4843 const [ selectedWeathers , setSelectedWeathers ] = useState ( [ ] ) ;
4944
5045 // Compute unique modes and weathers for dropdowns
5146 const allModes = useMemo ( ( ) => {
52- return Array . from ( new Set ( maps . map ( ( map ) => unifiedGamemodeName ( map . game_mode ) ) ) ) . sort ( ) ;
47+ return Array . from (
48+ new Set ( maps . map ( ( map ) => unifiedGamemodeName ( map . game_mode ) ) )
49+ ) . sort ( ) ;
5350 } , [ maps ] ) ;
5451
5552 const allWeather = useMemo ( ( ) => {
@@ -59,9 +56,15 @@ export const MapFilter = ({ maps, onFilterChange }) => {
5956 // Compute filtered maps based on filter criteria
6057 const filteredMaps = useMemo ( ( ) => {
6158 return maps . filter ( ( mapLayer ) => {
62- const matchesSearch = mapLayer . map . pretty_name . toLowerCase ( ) . includes ( searchTerm . toLowerCase ( ) ) ;
63- const matchesModes = ! selectedModes . length || selectedModes . includes ( unifiedGamemodeName ( mapLayer . game_mode ) ) ;
64- const matchesWeather = ! selectedWeathers . length || selectedWeathers . includes ( mapLayer . environment ) ;
59+ const matchesSearch = mapLayer . map . pretty_name
60+ . toLowerCase ( )
61+ . includes ( searchTerm . toLowerCase ( ) ) ;
62+ const matchesModes =
63+ ! selectedModes . length ||
64+ selectedModes . includes ( unifiedGamemodeName ( mapLayer . game_mode ) ) ;
65+ const matchesWeather =
66+ ! selectedWeathers . length ||
67+ selectedWeathers . includes ( mapLayer . environment ) ;
6568 return matchesSearch && matchesModes && matchesWeather ;
6669 } ) ;
6770 } , [ maps , searchTerm , selectedModes , selectedWeathers ] ) ;
@@ -71,62 +74,102 @@ export const MapFilter = ({ maps, onFilterChange }) => {
7174 onFilterChange ( filteredMaps ) ;
7275 } , [ filteredMaps , onFilterChange ] ) ;
7376
77+ const handleModeChange = ( mode ) => {
78+ setSelectedModes ( ( prev ) =>
79+ prev . includes ( mode ) ? prev . filter ( ( m ) => m !== mode ) : [ ...prev , mode ]
80+ ) ;
81+ } ;
82+
83+ const handleWeatherChange = ( weather ) => {
84+ setSelectedWeathers ( ( prev ) =>
85+ prev . includes ( weather )
86+ ? prev . filter ( ( w ) => w !== weather )
87+ : [ ...prev , weather ]
88+ ) ;
89+ } ;
90+
7491 return (
7592 < Stack
7693 alignItems = { "center" }
7794 flexWrap = { "wrap" }
7895 gap = { 1 }
7996 direction = { "row" }
80- sx = { { py : 1 , gap : 1 } }
97+ sx = { {
98+ py : 1 ,
99+ gap : 1 ,
100+ // Card-like styles
101+ borderRadius : 1 ,
102+ boxShadow : 1 ,
103+ border : '1px solid' ,
104+ borderColor : 'divider' ,
105+ p : 2 ,
106+ mb : 2
107+ } }
81108 >
82109 < DebouncedSearchInput
83110 size = "small"
84111 placeholder = "Search maps..."
85112 onChange = { setSearchTerm }
86113 />
87114
88- < Stack direction = { "row" } sx = { { gap : 1 , mb : 2 , width : "100%" } } >
89- < FormControl size = "small" sx = { { width : { xs : "100%" , md : "50%" } } } >
90- < InputLabel id = { "game-mode" } > Game Mode</ InputLabel >
91- < Select
92- labelId = { "game-mode" }
93- value = { selectedModes }
94- onChange = { ( e ) => setSelectedModes ( e . target . value ) }
95- multiple
96- renderValue = { ( selected ) => selected . join ( ", " ) }
97- input = { < OutlinedInput label = "Game Mode" /> }
98- MenuProps = { MenuProps }
99- SelectDisplayProps = { { style : { display : "block" , textTransform : "uppercase" } } }
115+ < Stack direction = { "column" } sx = { { width : "100%" , px : 1 } } >
116+ < Stack direction = { "row" } gap = { 1 } alignItems = { "center" } >
117+ < Typography
118+ variant = "subtitle2"
119+ fontSize = { 10 }
120+ sx = { { textTransform : "uppercase" , width : 70 } }
100121 >
122+ Game Mode
123+ </ Typography >
124+ < Stack direction = { "row" } flexWrap = { "wrap" } >
101125 { allModes . map ( ( mode ) => (
102- < MenuItem key = { mode } value = { mode } >
103- < Checkbox checked = { selectedModes . includes ( mode ) } />
104- < ListItemText primary = { unifiedGamemodeName ( mode ) } />
105- </ MenuItem >
126+ < FormControlLabel
127+ key = { mode }
128+ control = {
129+ < Checkbox
130+ checked = { selectedModes . includes ( mode ) }
131+ onChange = { ( ) => handleModeChange ( mode ) }
132+ size = "small"
133+ sx = { {
134+ "& .MuiSvgIcon-root" : { fontSize : 14 } ,
135+ } }
136+ />
137+ }
138+ label = { unifiedGamemodeName ( mode ) }
139+ sx = { { textTransform : "uppercase" , '& .MuiFormControlLabel-label' : { fontSize : 10 } } }
140+ />
106141 ) ) }
107- </ Select >
108- </ FormControl >
142+ </ Stack >
143+ </ Stack >
109144
110- < FormControl size = "small" sx = { { width : { xs : "100%" , md : "50%" } } } >
111- < InputLabel id = { "game-weather" } > Weather</ InputLabel >
112- < Select
113- labelId = { "game-weather" }
114- value = { selectedWeathers }
115- onChange = { ( e ) => setSelectedWeathers ( e . target . value ) }
116- multiple
117- renderValue = { ( selected ) => selected . join ( ", " ) }
118- input = { < OutlinedInput label = "Weather" /> }
119- MenuProps = { MenuProps }
120- SelectDisplayProps = { { style : { display : "block" , textTransform : "uppercase" } } }
145+ < Stack direction = { "row" } gap = { 1 } alignItems = { "center" } >
146+ < Typography
147+ variant = "subtitle2"
148+ fontSize = { 10 }
149+ sx = { { textTransform : "uppercase" , width : 70 } }
121150 >
151+ Weather
152+ </ Typography >
153+ < Stack direction = { "row" } flexWrap = { "wrap" } >
122154 { allWeather . map ( ( weather ) => (
123- < MenuItem key = { weather } value = { weather } >
124- < Checkbox checked = { selectedWeathers . includes ( weather ) } />
125- < ListItemText primary = { weather } />
126- </ MenuItem >
155+ < FormControlLabel
156+ key = { weather }
157+ control = {
158+ < Checkbox
159+ checked = { selectedWeathers . includes ( weather ) }
160+ onChange = { ( ) => handleWeatherChange ( weather ) }
161+ size = "small"
162+ sx = { {
163+ "& .MuiSvgIcon-root" : { fontSize : 14 } ,
164+ } }
165+ />
166+ }
167+ label = { weather }
168+ sx = { { textTransform : "uppercase" , '& .MuiFormControlLabel-label' : { fontSize : 10 } } }
169+ />
127170 ) ) }
128- </ Select >
129- </ FormControl >
171+ </ Stack >
172+ </ Stack >
130173 </ Stack >
131174 </ Stack >
132175 ) ;
0 commit comments