2021-07-21 23:16:44 -04:00
|
|
|
import { useState } from "react";
|
|
|
|
import SelectionMenu from "../components/selection/SelectionMenu";
|
|
|
|
import SelectTool from "../components/tools/SelectTool";
|
|
|
|
import { SelectionItemsChangeEventHandler } from "../types/Events";
|
|
|
|
import { Map, MapToolId } from "../types/Map";
|
2021-07-22 01:21:36 -04:00
|
|
|
import { MapState } from "../types/MapState";
|
2021-07-21 23:16:44 -04:00
|
|
|
import { Selection } from "../types/Select";
|
|
|
|
import { SelectToolSettings } from "../types/Select";
|
|
|
|
|
|
|
|
function useMapSelection(
|
|
|
|
map: Map | null,
|
2021-07-22 01:21:36 -04:00
|
|
|
mapState: MapState | null,
|
2021-07-21 23:16:44 -04:00
|
|
|
onSelectionItemsChange: SelectionItemsChangeEventHandler,
|
|
|
|
selectedToolId: MapToolId,
|
|
|
|
settings: SelectToolSettings
|
|
|
|
) {
|
|
|
|
const [isSelectionMenuOpen, setIsSelectionMenuOpen] =
|
|
|
|
useState<boolean>(false);
|
|
|
|
const [selection, setSelection] = useState<Selection | null>(null);
|
|
|
|
|
|
|
|
function handleSelectionMenuOpen(open: boolean) {
|
|
|
|
setIsSelectionMenuOpen(open);
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectionTool = (
|
|
|
|
<SelectTool
|
|
|
|
active={selectedToolId === "select"}
|
|
|
|
toolSettings={settings}
|
|
|
|
onSelectionItemsChange={onSelectionItemsChange}
|
|
|
|
selection={selection}
|
|
|
|
onSelectionChange={setSelection}
|
|
|
|
onSelectionMenuOpen={handleSelectionMenuOpen}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const selectionMenu = (
|
|
|
|
<SelectionMenu
|
|
|
|
isOpen={isSelectionMenuOpen}
|
|
|
|
onRequestClose={() => setIsSelectionMenuOpen(false)}
|
|
|
|
selection={selection}
|
|
|
|
onSelectionItemsChange={onSelectionItemsChange}
|
|
|
|
map={map}
|
2021-07-22 01:21:36 -04:00
|
|
|
mapState={mapState}
|
2021-07-21 23:16:44 -04:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return { selectionTool, selectionMenu };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default useMapSelection;
|