From 1e2619345782c9977108ce5766a9a88b3a9ded85 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Mon, 14 Jun 2021 15:18:07 +1000 Subject: [PATCH] Optimise token database sync and add loading indicator for multiple token hiding --- src/components/map/MapTiles.js | 34 ++++++++++++++----------- src/components/token/TokenEditBar.js | 9 ++++++- src/components/token/TokenTiles.js | 38 +++++++++++++++------------- src/contexts/TokenDataContext.js | 37 +++++++++++++++++---------- 4 files changed, 72 insertions(+), 46 deletions(-) diff --git a/src/components/map/MapTiles.js b/src/components/map/MapTiles.js index 3adeba6..044575e 100644 --- a/src/components/map/MapTiles.js +++ b/src/components/map/MapTiles.js @@ -20,21 +20,25 @@ function MapTiles({ mapsById, onMapEdit, onMapSelect, subgroup }) { function renderTile(group) { if (group.type === "item") { const map = mapsById[group.id]; - const isSelected = selectedGroupIds.includes(group.id); - const canEdit = - isSelected && selectMode === "single" && selectedGroupIds.length === 1; - return ( - canEdit && onMapSelect(group.id)} - canEdit={canEdit} - badges={[`${map.grid.size.x}x${map.grid.size.y}`]} - /> - ); + if (map) { + const isSelected = selectedGroupIds.includes(group.id); + const canEdit = + isSelected && + selectMode === "single" && + selectedGroupIds.length === 1; + return ( + canEdit && onMapSelect(group.id)} + canEdit={canEdit} + badges={[`${map.grid.size.x}x${map.grid.size.y}`]} + /> + ); + } } else { const isSelected = selectedGroupIds.includes(group.id); const items = getGroupItems(group); diff --git a/src/components/token/TokenEditBar.js b/src/components/token/TokenEditBar.js index a759739..1150269 100644 --- a/src/components/token/TokenEditBar.js +++ b/src/components/token/TokenEditBar.js @@ -48,7 +48,14 @@ function TokenEditBar({ disabled, onLoad }) { async function handleTokensHide(hideInSidebar) { const selectedTokens = getSelectedTokens(); const selectedTokenIds = selectedTokens.map((token) => token.id); - updateTokensHidden(selectedTokenIds, hideInSidebar); + // Show loading indicator if hiding more than 10 tokens + if (selectedTokenIds.length > 10) { + onLoad(true); + await updateTokensHidden(selectedTokenIds, hideInSidebar); + onLoad(false); + } else { + updateTokensHidden(selectedTokenIds, hideInSidebar); + } } /** diff --git a/src/components/token/TokenTiles.js b/src/components/token/TokenTiles.js index 02d5059..e61277c 100644 --- a/src/components/token/TokenTiles.js +++ b/src/components/token/TokenTiles.js @@ -21,24 +21,28 @@ function TokenTiles({ tokensById, onTokenEdit, subgroup }) { function renderTile(group) { if (group.type === "item") { const token = tokensById[group.id]; - const isSelected = selectedGroupIds.includes(group.id); - const canEdit = - isSelected && selectMode === "single" && selectedGroupIds.length === 1; + if (token) { + const isSelected = selectedGroupIds.includes(group.id); + const canEdit = + isSelected && + selectMode === "single" && + selectedGroupIds.length === 1; - return ( -