Added multi map remove to map data context
This commit is contained in:
parent
29ce562d01
commit
99b2bd0240
@ -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,
|
||||
|
@ -48,7 +48,7 @@ function SelectMapModal({
|
||||
ownedMaps,
|
||||
mapStates,
|
||||
addMap,
|
||||
removeMap,
|
||||
removeMaps,
|
||||
resetMap,
|
||||
updateMap,
|
||||
} = useContext(MapDataContext);
|
||||
@ -199,9 +199,7 @@ function SelectMapModal({
|
||||
}
|
||||
|
||||
async function handleMapsRemove() {
|
||||
for (let id of selectedMapIds) {
|
||||
await removeMap(id);
|
||||
}
|
||||
await removeMaps(selectedMapIds);
|
||||
setSelectedMapIds([]);
|
||||
// Removed the map from the map screen if needed
|
||||
if (currentMap && selectedMapIds.includes(currentMap.id)) {
|
||||
|
Loading…
Reference in New Issue
Block a user