Fix memory async error with map tile double click and default map selection bug

This commit is contained in:
Mitchell McCaffrey 2020-04-26 19:22:30 +10:00
parent 29f13262ff
commit f371a62a04
2 changed files with 12 additions and 5 deletions

View File

@ -101,11 +101,12 @@ function MapTile({
bg="muted"
onClick={() => {
setIsTileMenuOpen(false);
onMapSelect(map);
if (!isSelected) {
onMapSelect(map);
}
}}
onDoubleClick={(e) => {
if (!isMapTileMenuOpen) {
onMapSelect(map);
onSubmit(e);
}
}}

View File

@ -87,8 +87,12 @@ function SelectMapModal({
if (selectedMap) {
const map = await db.table("maps").get(selectedMap.id);
const state = await db.table("states").get(selectedMap.id);
setSelectedMap(map);
setSelectedMapState(state);
if (map) {
setSelectedMap(map);
}
if (state) {
setSelectedMapState(state);
}
}
}
@ -184,13 +188,15 @@ function SelectMapModal({
}
async function handleMapSelect(map) {
setSelectedMapState(await db.table("states").get(map.id));
const state = await db.table("states").get(map.id);
setSelectedMapState(state);
setSelectedMap(map);
}
async function handleMapReset(id) {
const state = { ...defaultMapState, mapId: id };
await db.table("states").put(state);
setSelectedMapState(state);
// Reset the state of the current map if needed
if (currentMap && currentMap.id === selectedMap.id) {
onMapStateChange(state);