@@ -47,32 +47,30 @@ export const MapFilter = ({ maps, onFilterChange }) => {
4747 const [ selectedModes , setSelectedModes ] = useState ( [ ] ) ;
4848 const [ selectedWeathers , setSelectedWeathers ] = useState ( [ ] ) ;
4949
50+ // Compute unique modes and weathers for dropdowns
5051 const allModes = useMemo ( ( ) => {
51- if ( maps . length === 0 ) return [ "warfare" ] ; // default value before maps load
5252 return Array . from ( new Set ( maps . map ( ( map ) => unifiedGamemodeName ( map . game_mode ) ) ) ) . sort ( ) ;
5353 } , [ maps ] ) ;
5454
5555 const allWeather = useMemo ( ( ) => {
56- if ( maps . length === 0 ) return [ "day" ] ; // default value before maps load
5756 return Array . from ( new Set ( maps . map ( ( map ) => map . environment ) ) ) . sort ( ) ;
5857 } , [ maps ] ) ;
5958
60- useEffect ( ( ) => {
61- // Filter map variants based on search term and filters
62- const filteredMaps = maps . filter ( ( mapLayer ) => {
63- const matchesSearch = mapLayer . map . pretty_name
64- . toLowerCase ( )
65- . includes ( searchTerm . toLowerCase ( ) ) ;
66- const matchesModes =
67- ! selectedModes . length || selectedModes . includes ( unifiedGamemodeName ( mapLayer . game_mode ) ) ;
68- const matchesWeather =
69- ! selectedWeathers . length ||
70- selectedWeathers . includes ( mapLayer . environment ) ;
59+ // Compute filtered maps based on filter criteria
60+ const filteredMaps = useMemo ( ( ) => {
61+ 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 ) ;
7165 return matchesSearch && matchesModes && matchesWeather ;
7266 } ) ;
73- onFilterChange ( filteredMaps ) ;
7467 } , [ maps , searchTerm , selectedModes , selectedWeathers ] ) ;
7568
69+ // Notify parent of filter changes
70+ useEffect ( ( ) => {
71+ onFilterChange ( filteredMaps ) ;
72+ } , [ filteredMaps , onFilterChange ] ) ;
73+
7674 return (
7775 < Stack
7876 alignItems = { "center" }
0 commit comments