Add remove group items for maps and tokens
This commit is contained in:
parent
1ec67c7a0f
commit
ee34c599da
@ -62,8 +62,8 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
|
|||||||
setIsMapsRemoveModalOpen(false);
|
setIsMapsRemoveModalOpen(false);
|
||||||
const selectedMaps = getSelectedMaps();
|
const selectedMaps = getSelectedMaps();
|
||||||
const selectedMapIds = selectedMaps.map((map) => map.id);
|
const selectedMapIds = selectedMaps.map((map) => map.id);
|
||||||
await removeMaps(selectedMapIds);
|
|
||||||
onGroupSelect();
|
onGroupSelect();
|
||||||
|
await removeMaps(selectedMapIds);
|
||||||
// Removed the map from the map screen if needed
|
// Removed the map from the map screen if needed
|
||||||
if (currentMap && selectedMapIds.includes(currentMap.id)) {
|
if (currentMap && selectedMapIds.includes(currentMap.id)) {
|
||||||
onMapChange(null, null);
|
onMapChange(null, null);
|
||||||
|
@ -44,8 +44,8 @@ function TokenEditBar({ disabled, onLoad }) {
|
|||||||
setIsTokensRemoveModalOpen(false);
|
setIsTokensRemoveModalOpen(false);
|
||||||
const selectedTokens = getSelectedTokens();
|
const selectedTokens = getSelectedTokens();
|
||||||
const selectedTokenIds = selectedTokens.map((token) => token.id);
|
const selectedTokenIds = selectedTokens.map((token) => token.id);
|
||||||
await removeTokens(selectedTokenIds);
|
|
||||||
onGroupSelect();
|
onGroupSelect();
|
||||||
|
await removeTokens(selectedTokenIds);
|
||||||
onLoad(false);
|
onLoad(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import { useAuth } from "./AuthContext";
|
|||||||
import { useDatabase } from "./DatabaseContext";
|
import { useDatabase } from "./DatabaseContext";
|
||||||
|
|
||||||
import { applyObservableChange } from "../helpers/dexie";
|
import { applyObservableChange } from "../helpers/dexie";
|
||||||
|
import { removeGroupsItems } from "../helpers/group";
|
||||||
|
|
||||||
const MapDataContext = React.createContext();
|
const MapDataContext = React.createContext();
|
||||||
|
|
||||||
@ -105,6 +106,11 @@ export function MapDataProvider({ children }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const group = await database.table("groups").get("maps");
|
||||||
|
let items = removeGroupsItems(group.items, ids);
|
||||||
|
await database.table("groups").update("maps", { items });
|
||||||
|
|
||||||
await database.table("maps").bulkDelete(ids);
|
await database.table("maps").bulkDelete(ids);
|
||||||
await database.table("states").bulkDelete(ids);
|
await database.table("states").bulkDelete(ids);
|
||||||
await database.table("assets").bulkDelete(assetIds);
|
await database.table("assets").bulkDelete(assetIds);
|
||||||
|
@ -5,6 +5,7 @@ import { useAuth } from "./AuthContext";
|
|||||||
import { useDatabase } from "./DatabaseContext";
|
import { useDatabase } from "./DatabaseContext";
|
||||||
|
|
||||||
import { applyObservableChange } from "../helpers/dexie";
|
import { applyObservableChange } from "../helpers/dexie";
|
||||||
|
import { removeGroupsItems } from "../helpers/group";
|
||||||
|
|
||||||
const TokenDataContext = React.createContext();
|
const TokenDataContext = React.createContext();
|
||||||
|
|
||||||
@ -73,6 +74,11 @@ export function TokenDataProvider({ children }) {
|
|||||||
assetIds.push(token.thumbnail);
|
assetIds.push(token.thumbnail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const group = await database.table("groups").get("tokens");
|
||||||
|
let items = removeGroupsItems(group.items, ids);
|
||||||
|
await database.table("groups").update("tokens", { items });
|
||||||
|
|
||||||
await database.table("tokens").bulkDelete(ids);
|
await database.table("tokens").bulkDelete(ids);
|
||||||
await database.table("assets").bulkDelete(assetIds);
|
await database.table("assets").bulkDelete(assetIds);
|
||||||
},
|
},
|
||||||
|
@ -236,3 +236,31 @@ export function renameGroup(groups, groupId, newName) {
|
|||||||
}
|
}
|
||||||
return newGroups;
|
return newGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove items from groups including sub groups
|
||||||
|
* @param {Group[]} groups
|
||||||
|
* @param {string[]} itemIds
|
||||||
|
*/
|
||||||
|
export function removeGroupsItems(groups, itemIds) {
|
||||||
|
let newGroups = cloneDeep(groups);
|
||||||
|
|
||||||
|
for (let i = newGroups.length - 1; i >= 0; i--) {
|
||||||
|
const group = newGroups[i];
|
||||||
|
if (group.type === "item") {
|
||||||
|
if (itemIds.includes(group.id)) {
|
||||||
|
newGroups.splice(i, 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const items = group.items;
|
||||||
|
for (let j = items.length - 1; j >= 0; j--) {
|
||||||
|
const item = items[j];
|
||||||
|
if (itemIds.includes(item.id)) {
|
||||||
|
newGroups[i].items.splice(j, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newGroups;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user