Added multi map remove to map data context

This commit is contained in:
Mitchell McCaffrey
2020-09-30 15:44:48 +10:00
parent 29ce562d01
commit 99b2bd0240
2 changed files with 18 additions and 4 deletions

View File

@@ -101,6 +101,21 @@ export function MapDataProvider({ children }) {
});
}
async function removeMaps(ids) {
await database.table("maps").bulkDelete(ids);
await database.table("states").bulkDelete(ids);
setMaps((prevMaps) => {
const filtered = prevMaps.filter((map) => !ids.includes(map.id));
return filtered;
});
setMapStates((prevMapsStates) => {
const filtered = prevMapsStates.filter(
(state) => !ids.includes(state.mapId)
);
return filtered;
});
}
async function resetMap(id) {
const state = { ...defaultMapState, mapId: id };
await database.table("states").put(state);
@@ -199,6 +214,7 @@ export function MapDataProvider({ children }) {
mapStates,
addMap,
removeMap,
removeMaps,
resetMap,
updateMap,
updateMapState,