Remove delete restriction for default maps and tokens
This commit is contained in:
parent
dab655935f
commit
159627072d
@ -16,7 +16,6 @@ import shortcuts from "../../shortcuts";
|
|||||||
|
|
||||||
function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
|
function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
|
||||||
const [hasMapState, setHasMapState] = useState(false);
|
const [hasMapState, setHasMapState] = useState(false);
|
||||||
const [hasSelectedDefaultMap, setHasSelectedDefaultMap] = useState(false);
|
|
||||||
|
|
||||||
const { maps, mapStates, removeMaps, resetMap } = useMapData();
|
const { maps, mapStates, removeMaps, resetMap } = useMapData();
|
||||||
|
|
||||||
@ -24,17 +23,12 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
|
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
|
||||||
const selectedMaps = itemsFromGroups(selectedGroups, maps);
|
|
||||||
const selectedMapStates = itemsFromGroups(
|
const selectedMapStates = itemsFromGroups(
|
||||||
selectedGroups,
|
selectedGroups,
|
||||||
mapStates,
|
mapStates,
|
||||||
"mapId"
|
"mapId"
|
||||||
);
|
);
|
||||||
|
|
||||||
setHasSelectedDefaultMap(
|
|
||||||
selectedMaps.some((map) => map.type === "default")
|
|
||||||
);
|
|
||||||
|
|
||||||
let _hasMapState = false;
|
let _hasMapState = false;
|
||||||
for (let state of selectedMapStates) {
|
for (let state of selectedMapStates) {
|
||||||
if (
|
if (
|
||||||
@ -49,7 +43,7 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setHasMapState(_hasMapState);
|
setHasMapState(_hasMapState);
|
||||||
}, [selectedGroupIds, maps, mapStates, activeGroups]);
|
}, [selectedGroupIds, mapStates, activeGroups]);
|
||||||
|
|
||||||
function getSelectedMaps() {
|
function getSelectedMaps() {
|
||||||
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
|
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
|
||||||
@ -96,11 +90,7 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
|
|||||||
}
|
}
|
||||||
if (shortcuts.delete(event)) {
|
if (shortcuts.delete(event)) {
|
||||||
const selectedMaps = getSelectedMaps();
|
const selectedMaps = getSelectedMaps();
|
||||||
// Selected maps and none are default
|
if (selectedMaps.length > 0) {
|
||||||
if (
|
|
||||||
selectedMaps.length > 0 &&
|
|
||||||
!selectedMaps.some((map) => map.type === "default")
|
|
||||||
) {
|
|
||||||
setIsMapsResetModalOpen(false);
|
setIsMapsResetModalOpen(false);
|
||||||
setIsMapsRemoveModalOpen(true);
|
setIsMapsRemoveModalOpen(true);
|
||||||
}
|
}
|
||||||
@ -142,7 +132,6 @@ function MapEditBar({ currentMap, disabled, onMapChange, onMapReset, onLoad }) {
|
|||||||
aria-label="Remove Selected Map(s)"
|
aria-label="Remove Selected Map(s)"
|
||||||
title="Remove Selected Map(s)"
|
title="Remove Selected Map(s)"
|
||||||
onClick={() => setIsMapsRemoveModalOpen(true)}
|
onClick={() => setIsMapsRemoveModalOpen(true)}
|
||||||
disabled={hasSelectedDefaultMap}
|
|
||||||
>
|
>
|
||||||
<RemoveMapIcon />
|
<RemoveMapIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
@ -20,16 +20,12 @@ function TokenEditBar({ disabled, onLoad }) {
|
|||||||
|
|
||||||
const { activeGroups, selectedGroupIds, onGroupSelect } = useGroup();
|
const { activeGroups, selectedGroupIds, onGroupSelect } = useGroup();
|
||||||
|
|
||||||
const [hasSelectedDefaultToken, setHasSelectedDefaultToken] = useState(false);
|
|
||||||
const [allTokensVisible, setAllTokensVisisble] = useState(false);
|
const [allTokensVisible, setAllTokensVisisble] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
|
const selectedGroups = groupsFromIds(selectedGroupIds, activeGroups);
|
||||||
const selectedTokens = itemsFromGroups(selectedGroups, tokens);
|
const selectedTokens = itemsFromGroups(selectedGroups, tokens);
|
||||||
|
|
||||||
setHasSelectedDefaultToken(
|
|
||||||
selectedTokens.some((token) => token.type === "default")
|
|
||||||
);
|
|
||||||
setAllTokensVisisble(selectedTokens.every((token) => !token.hideInSidebar));
|
setAllTokensVisisble(selectedTokens.every((token) => !token.hideInSidebar));
|
||||||
}, [selectedGroupIds, tokens, activeGroups]);
|
}, [selectedGroupIds, tokens, activeGroups]);
|
||||||
|
|
||||||
@ -64,11 +60,7 @@ function TokenEditBar({ disabled, onLoad }) {
|
|||||||
}
|
}
|
||||||
if (shortcuts.delete(event)) {
|
if (shortcuts.delete(event)) {
|
||||||
const selectedTokens = getSelectedTokens();
|
const selectedTokens = getSelectedTokens();
|
||||||
// Selected tokens and none are default
|
if (selectedTokens.length > 0) {
|
||||||
if (
|
|
||||||
selectedTokens.length > 0 &&
|
|
||||||
!selectedTokens.some((token) => token.type === "default")
|
|
||||||
) {
|
|
||||||
// Ensure all other modals are closed
|
// Ensure all other modals are closed
|
||||||
setIsTokensRemoveModalOpen(true);
|
setIsTokensRemoveModalOpen(true);
|
||||||
}
|
}
|
||||||
@ -116,7 +108,6 @@ function TokenEditBar({ disabled, onLoad }) {
|
|||||||
aria-label="Remove Selected Token(s)"
|
aria-label="Remove Selected Token(s)"
|
||||||
title="Remove Selected Token(s)"
|
title="Remove Selected Token(s)"
|
||||||
onClick={() => handleTokensRemove()}
|
onClick={() => handleTokensRemove()}
|
||||||
disabled={hasSelectedDefaultToken}
|
|
||||||
>
|
>
|
||||||
<RemoveTokenIcon />
|
<RemoveTokenIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
Loading…
Reference in New Issue
Block a user