Skip to content

Commit bc43bac

Browse files
committed
Improve initial builder lists render desync
1 parent 6596451 commit bc43bac

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

rcongui/src/pages/settings/maps/MapFilter.jsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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"}

rcongui/src/pages/settings/maps/MapListBuilder.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ export function MapListBuilder({
4040
exclusive = false,
4141
actions,
4242
}) {
43-
const [mapSelection, setMapSelection] = useState([]);
43+
const [mapSelection, setMapSelection] = useState(selectedMaps.map(withSelectionId));
44+
4445
const mapOptions = useMemo(() => {
4546
if (!exclusive) return allMaps;
4647
const selectedIds = new Set(mapSelection.map((m) => m.id));
4748
const exclusiveOptions = allMaps.filter((m) => !selectedIds.has(m.id));
4849
return exclusiveOptions;
4950
}, [exclusive, allMaps, mapSelection]);
50-
51+
5152
const [filteredMapOptions, setFilteredMapOptions] = useState(mapOptions);
5253

5354
const theme = useTheme();
@@ -58,11 +59,9 @@ export function MapListBuilder({
5859
const isMapSelectionVisible =
5960
!isSmallScreen || (isSmallScreen && view === "map-selection");
6061

61-
// Set selection data when it's loaded
62+
// Set selection data when it's changed by the parent
6263
useEffect(() => {
63-
if (selectedMaps.length > 0) {
64-
setMapSelection(selectedMaps.map(withSelectionId));
65-
}
64+
setMapSelection(selectedMaps.map(withSelectionId));
6665
}, [selectedMaps]);
6766

6867
const handleViewChange = (e, newView) => {

0 commit comments

Comments
 (0)