diff --git a/src/modals/EditMapModal.js b/src/modals/EditMapModal.js index c590102..a89ade8 100644 --- a/src/modals/EditMapModal.js +++ b/src/modals/EditMapModal.js @@ -19,7 +19,7 @@ function EditMapModal({ isOpen, onDone, mapId }) { updateMapState, getMap, getMapFromDB, - mapStates, + getMapStateFromDB, } = useMapData(); const [isLoading, setIsLoading] = useState(true); @@ -34,8 +34,9 @@ function EditMapModal({ isOpen, onDone, mapId }) { if (loadingMap?.type === "file" && !loadingMap?.file) { loadingMap = await getMapFromDB(mapId); } + const mapState = await getMapStateFromDB(mapId); setMap(loadingMap); - setMapState(mapStates.find((state) => state.mapId === mapId)); + setMapState(mapState); setIsLoading(false); } @@ -45,7 +46,7 @@ function EditMapModal({ isOpen, onDone, mapId }) { setMap(); setMapState(); } - }, [isOpen, mapId, getMapFromDB, mapStates, getMap]); + }, [isOpen, mapId, getMapFromDB, getMapStateFromDB, getMap]); function handleClose() { setMapSettingChanges({}); diff --git a/src/modals/SelectMapModal.js b/src/modals/SelectMapModal.js index f64b961..746dd5d 100644 --- a/src/modals/SelectMapModal.js +++ b/src/modals/SelectMapModal.js @@ -65,6 +65,7 @@ function SelectMapModal({ updateMaps, mapsLoading, getMapFromDB, + getMapStateFromDB, } = useMapData(); /** @@ -325,12 +326,13 @@ function SelectMapModal({ // Update last used for cache invalidation const lastUsed = Date.now(); const map = selectedMaps[0]; + const mapState = await getMapStateFromDB(map.id); if (map.type === "file") { await updateMap(map.id, { lastUsed }); const updatedMap = await getMapFromDB(map.id); - onMapChange(updatedMap, selectedMapStates[0]); + onMapChange(updatedMap, mapState); } else { - onMapChange(map, selectedMapStates[0]); + onMapChange(map, mapState); } } else { onMapChange(null, null);