Add check for selected items visible and locked properties
This commit is contained in:
parent
7860871e7e
commit
543fe6f941
@ -151,6 +151,7 @@ function Map({
|
||||
|
||||
const { selectionTool, selectionMenu } = useMapSelection(
|
||||
map,
|
||||
mapState,
|
||||
onSelectionItemsChange,
|
||||
selectedToolId,
|
||||
settings.select
|
||||
|
@ -23,6 +23,7 @@ import { Note } from "../../types/Note";
|
||||
import { getSelectionPoints } from "../../helpers/selection";
|
||||
import Vector2 from "../../helpers/Vector2";
|
||||
import { useMapStage } from "../../contexts/MapStageContext";
|
||||
import { MapState } from "../../types/MapState";
|
||||
|
||||
type SelectionMenuProps = {
|
||||
isOpen: boolean;
|
||||
@ -30,6 +31,7 @@ type SelectionMenuProps = {
|
||||
selection: Selection | null;
|
||||
onSelectionItemsChange: SelectionItemsChangeEventHandler;
|
||||
map: Map | null;
|
||||
mapState: MapState | null;
|
||||
};
|
||||
|
||||
function SelectionMenu({
|
||||
@ -38,6 +40,7 @@ function SelectionMenu({
|
||||
selection,
|
||||
onSelectionItemsChange,
|
||||
map,
|
||||
mapState,
|
||||
}: SelectionMenuProps) {
|
||||
const userId = useUserId();
|
||||
|
||||
@ -101,6 +104,34 @@ function SelectionMenu({
|
||||
setItemsLocked(!itemsLocked);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && selection && mapState) {
|
||||
let allVisible = true;
|
||||
let allLocked = true;
|
||||
for (let item of selection.items) {
|
||||
if (item.type === "token") {
|
||||
const tokenState = mapState.tokens[item.id];
|
||||
if (!tokenState.visible) {
|
||||
allVisible = false;
|
||||
}
|
||||
if (!tokenState.locked) {
|
||||
allLocked = false;
|
||||
}
|
||||
} else {
|
||||
const note = mapState.notes[item.id];
|
||||
if (!note.visible) {
|
||||
allVisible = false;
|
||||
}
|
||||
if (!note.locked) {
|
||||
allLocked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
setItemsVisible(allVisible);
|
||||
setItemsLocked(allLocked);
|
||||
}
|
||||
}, [mapState, selection, isOpen]);
|
||||
|
||||
function handleModalContent(node: HTMLElement) {
|
||||
if (node) {
|
||||
// Focus input
|
||||
|
@ -3,11 +3,13 @@ import SelectionMenu from "../components/selection/SelectionMenu";
|
||||
import SelectTool from "../components/tools/SelectTool";
|
||||
import { SelectionItemsChangeEventHandler } from "../types/Events";
|
||||
import { Map, MapToolId } from "../types/Map";
|
||||
import { MapState } from "../types/MapState";
|
||||
import { Selection } from "../types/Select";
|
||||
import { SelectToolSettings } from "../types/Select";
|
||||
|
||||
function useMapSelection(
|
||||
map: Map | null,
|
||||
mapState: MapState | null,
|
||||
onSelectionItemsChange: SelectionItemsChangeEventHandler,
|
||||
selectedToolId: MapToolId,
|
||||
settings: SelectToolSettings
|
||||
@ -38,6 +40,7 @@ function useMapSelection(
|
||||
selection={selection}
|
||||
onSelectionItemsChange={onSelectionItemsChange}
|
||||
map={map}
|
||||
mapState={mapState}
|
||||
/>
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user