Updated map state usage to use DB when selecting

This commit is contained in:
Mitchell McCaffrey 2021-02-14 16:32:03 +11:00
parent 53eb9b3c08
commit 265472311e
2 changed files with 8 additions and 5 deletions

View File

@ -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({});

View File

@ -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);