Reverted unnecessary changes to fix fake-indexeddb issue

This commit is contained in:
Mitchell McCaffrey 2020-10-24 09:05:16 +11:00
parent b59efda436
commit 05e66e5e82
3 changed files with 6 additions and 12 deletions

View File

@ -131,15 +131,13 @@ export function MapDataProvider({ children }) {
}
async function updateMap(id, update) {
// fake-indexeddb throws an error when updating maps
// TODO: find the root cause of the error
// fake-indexeddb throws an error when updating maps in production.
// Catch that error and use put when it fails
try {
await database.table("maps").update(id, update);
} catch (error) {
// Use put when update fails
const map = (await getMapFromDB(id)) || {};
await database.table("maps").put({ ...map, id, ...update });
console.error(error);
}
setMaps((prevMaps) => {
const newMaps = [...prevMaps];
@ -149,10 +147,6 @@ export function MapDataProvider({ children }) {
}
return newMaps;
});
// Return the updated map and ensure it has the update in it
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();
const updatedMap = await updateMap(selectedMapIds[0], { lastUsed });
onMapChange(updatedMap, selectedMapStates[0]);
await updateMap(selectedMapIds[0], { lastUsed });
onMapChange({ ...selectedMaps[0], lastUsed }, 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();
const updatedMap = await updateMap(cachedMap.id, { lastUsed });
setCurrentMap(updatedMap);
await updateMap(cachedMap.id, { lastUsed });
setCurrentMap({ ...cachedMap, lastUsed });
} 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