Remove delete restriction for default maps and tokens

This commit is contained in:
Mitchell McCaffrey 2021-06-11 15:33:14 +10:00
parent dab655935f
commit 159627072d
2 changed files with 3 additions and 23 deletions

View File

@ -16,7 +16,6 @@ import shortcuts from "../../shortcuts";
function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
const [hasMapState, setHasMapState] = useState(false);
const [hasSelectedDefaultMap, setHasSelectedDefaultMap] = useState(false);
const { maps, mapStates, removeMaps, resetMap } = useMapData();
@ -24,17 +23,12 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
useEffect(() => {
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
const selectedMaps = itemsFromGroups(selectedGroups, maps);
const selectedMapStates = itemsFromGroups(
selectedGroups,
mapStates,
"mapId"
);
setHasSelectedDefaultMap(
selectedMaps.some((map) => map.type === "default")
);
let _hasMapState = false;
for (let state of selectedMapStates) {
if (
@ -49,7 +43,7 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
}
setHasMapState(_hasMapState);
}, [selectedGroupIds, maps, mapStates, activeGroups]);
}, [selectedGroupIds, mapStates, activeGroups]);
function getSelectedMaps() {
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
@ -96,11 +90,7 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
}
if (shortcuts.delete(event)) {
const selectedMaps = getSelectedMaps();
// Selected maps and none are default
if (
selectedMaps.length > 0 &&
!selectedMaps.some((map) => map.type === "default")
) {
if (selectedMaps.length > 0) {
setIsMapsResetModalOpen(false);
setIsMapsRemoveModalOpen(true);
}
@ -142,7 +132,6 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
aria-label="Remove Selected Map(s)"
title="Remove Selected Map(s)"
onClick={() => setIsMapsRemoveModalOpen(true)}
disabled={hasSelectedDefaultMap}
>
<RemoveMapIcon />
</IconButton>

View File

@ -20,16 +20,12 @@ function TokenEditBar({ disabled, onLoad }) {
const { activeGroups, selectedGroupIds, onGroupSelect } = useGroup();
const [hasSelectedDefaultToken, setHasSelectedDefaultToken] = useState(false);
const [allTokensVisible, setAllTokensVisisble] = useState(false);
useEffect(() => {
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
const selectedTokens = itemsFromGroups(selectedGroups, tokens);
setHasSelectedDefaultToken(
selectedTokens.some((token) => token.type === "default")
);
setAllTokensVisisble(selectedTokens.every((token) => !token.hideInSidebar));
}, [selectedGroupIds, tokens, activeGroups]);
@ -64,11 +60,7 @@ function TokenEditBar({ disabled, onLoad }) {
}
if (shortcuts.delete(event)) {
const selectedTokens = getSelectedTokens();
// Selected tokens and none are default
if (
selectedTokens.length > 0 &&
!selectedTokens.some((token) => token.type === "default")
) {
if (selectedTokens.length > 0) {
// Ensure all other modals are closed
setIsTokensRemoveModalOpen(true);
}
@ -116,7 +108,6 @@ function TokenEditBar({ disabled, onLoad }) {
aria-label="Remove Selected Token(s)"
title="Remove Selected Token(s)"
onClick={() => handleTokensRemove()}
disabled={hasSelectedDefaultToken}
>
<RemoveTokenIcon />
</IconButton>