Updated update map

This commit is contained in:
Mitchell McCaffrey 2020-10-24 00:01:46 +11:00
parent b70bcdabd2
commit f8d7f7f19f
3 changed files with 9 additions and 8 deletions

View File

@ -145,7 +145,9 @@ export function MapDataProvider({ children }) {
}
return newMaps;
});
console.log("updated");
const updatedMap = (await database.table("maps").get(id)) || {};
return { ...updatedMap, ...update };
}
async function updateMaps(ids, update) {

View File

@ -280,8 +280,8 @@ function SelectMapModal({
if (selectedMapIds.length === 1) {
// Update last used for cache invalidation
const lastUsed = Date.now();
await updateMap(selectedMapIds[0], { lastUsed });
onMapChange({ ...selectedMaps[0], lastUsed }, selectedMapStates[0]);
const updatedMap = await updateMap(selectedMapIds[0], { lastUsed });
onMapChange(updatedMap, selectedMapStates[0]);
} else {
onMapChange(null, null);
}

View File

@ -247,8 +247,8 @@ function NetworkedMapAndTokens({ session }) {
if (cachedMap && cachedMap.lastModified >= newMap.lastModified) {
// Update last used for cache invalidation
const lastUsed = Date.now();
await updateMap(cachedMap.id, { lastUsed });
setCurrentMap({ ...cachedMap, lastUsed });
const updatedMap = await updateMap(cachedMap.id, { lastUsed });
setCurrentMap(updatedMap);
} else {
// Save map data but remove last modified so if there is an error
// during the map request the cache is invalid. Also add last used
@ -319,9 +319,8 @@ function NetworkedMapAndTokens({ session }) {
}
if (id === "mapResponse") {
const { id, ...update } = data;
await updateMap(id, update);
const newMap = await getMapFromDB(data.id);
setCurrentMap(newMap);
const updatedMap = await updateMap(id, update);
setCurrentMap(updatedMap);
}
if (id === "mapState") {
setCurrentMapState(data);