Delete assets with maps and token
This commit is contained in:
parent
acbb00dc5b
commit
04cf5687dd
@ -64,7 +64,6 @@ export function MapDataProvider({ children }) {
|
||||
return defaultMapsWithIds;
|
||||
}
|
||||
|
||||
// Loads maps without the file data to save memory
|
||||
async function loadMaps() {
|
||||
let storedMaps = [];
|
||||
// Try to load maps with worker, fallback to database if failed
|
||||
@ -75,8 +74,7 @@ export function MapDataProvider({ children }) {
|
||||
} else {
|
||||
console.warn("Unable to load maps with worker, loading may be slow");
|
||||
await database.table("maps").each((map) => {
|
||||
const { file, resolutions, ...rest } = map;
|
||||
storedMaps.push(rest);
|
||||
storedMaps.push(map);
|
||||
});
|
||||
}
|
||||
const sortedMaps = storedMaps.sort((a, b) => b.created - a.created);
|
||||
@ -152,18 +150,23 @@ export function MapDataProvider({ children }) {
|
||||
[database, updateCache, userId]
|
||||
);
|
||||
|
||||
const removeMap = useCallback(
|
||||
async (id) => {
|
||||
await database.table("maps").delete(id);
|
||||
await database.table("states").delete(id);
|
||||
},
|
||||
[database]
|
||||
);
|
||||
|
||||
const removeMaps = useCallback(
|
||||
async (ids) => {
|
||||
const maps = await database.table("maps").bulkGet(ids);
|
||||
// Remove assets linked with maps
|
||||
let assetIds = [];
|
||||
for (let map of maps) {
|
||||
if (map.type === "file") {
|
||||
assetIds.push(map.file);
|
||||
assetIds.push(map.thumbnail);
|
||||
for (let res of Object.values(map.resolutions)) {
|
||||
assetIds.push(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
await database.table("maps").bulkDelete(ids);
|
||||
await database.table("states").bulkDelete(ids);
|
||||
await database.table("assets").bulkDelete(assetIds);
|
||||
},
|
||||
[database]
|
||||
);
|
||||
@ -293,7 +296,6 @@ export function MapDataProvider({ children }) {
|
||||
ownedMaps,
|
||||
mapStates,
|
||||
addMap,
|
||||
removeMap,
|
||||
removeMaps,
|
||||
resetMap,
|
||||
updateMap,
|
||||
|
@ -49,8 +49,7 @@ export function TokenDataProvider({ children }) {
|
||||
} else {
|
||||
console.warn("Unable to load tokens with worker, loading may be slow");
|
||||
await database.table("tokens").each((token) => {
|
||||
const { file, resolutions, ...rest } = token;
|
||||
storedTokens.push(rest);
|
||||
storedTokens.push(token);
|
||||
});
|
||||
}
|
||||
const sortedTokens = storedTokens.sort((a, b) => b.created - a.created);
|
||||
@ -109,16 +108,18 @@ export function TokenDataProvider({ children }) {
|
||||
[database, updateCache, userId]
|
||||
);
|
||||
|
||||
const removeToken = useCallback(
|
||||
async (id) => {
|
||||
await database.table("tokens").delete(id);
|
||||
},
|
||||
[database]
|
||||
);
|
||||
|
||||
const removeTokens = useCallback(
|
||||
async (ids) => {
|
||||
const tokens = await database.table("tokens").bulkGet(ids);
|
||||
let assetIds = [];
|
||||
for (let token of tokens) {
|
||||
if (token.type === "file") {
|
||||
assetIds.push(token.file);
|
||||
assetIds.push(token.thumbnail);
|
||||
}
|
||||
}
|
||||
await database.table("tokens").bulkDelete(ids);
|
||||
await database.table("assets").bulkDelete(assetIds);
|
||||
},
|
||||
[database]
|
||||
);
|
||||
@ -205,7 +206,6 @@ export function TokenDataProvider({ children }) {
|
||||
tokens,
|
||||
ownedTokens,
|
||||
addToken,
|
||||
removeToken,
|
||||
removeTokens,
|
||||
updateToken,
|
||||
updateTokens,
|
||||
|
Loading…
Reference in New Issue
Block a user