1 | import React, {useState, useEffect} from "react";
|
---|
2 | import styles from "./EntranceModal.module.css";
|
---|
3 | import PropTypes from "prop-types";
|
---|
4 | import {MapBuilder} from "../../../scripts/main/MapBuilder.js";
|
---|
5 |
|
---|
6 | import Modal from "../Components/Modal.jsx";
|
---|
7 | import ModalNameField from "../Components/ModalNameField.jsx";
|
---|
8 | import ModalSelectRoom from "../Components/ModalSelectRoom.jsx";
|
---|
9 | import ModalSelectConnections from "../Components/ModalSelectConnections.jsx";
|
---|
10 | import ModalDisplayConnections from "../Components/ModalDisplayConnections.jsx";
|
---|
11 | import ModalDescriptionField from "../Components/ModalDescriptionField.jsx";
|
---|
12 | import ModalSaveButton from "../Components/ModalSaveButton.jsx";
|
---|
13 | import ModalMainEntranceCheckbox from "../Components/ModalMainEntranceCheckbox.jsx";
|
---|
14 | import {useModalEvent} from "../Hooks/useModalEvent.jsx";
|
---|
15 | import useModalState from "../Hooks/useModalState.jsx";
|
---|
16 | import useConnections from "../Hooks/useConnections.jsx";
|
---|
17 | import ModalSelectConnections2 from "../Components/ModalSelectConnections2.jsx";
|
---|
18 | import ShapeQuery from "../../../scripts/util/ShapeQuery.js";
|
---|
19 |
|
---|
20 | export default function EntranceModal({map}) {
|
---|
21 |
|
---|
22 | const {
|
---|
23 | modalState: {isOpen,setIsOpen,shape,setShape,shapeInfo,setShapeInfo},
|
---|
24 | handlers: {toggleModal,updateModalData,saveDetails}
|
---|
25 | } = useModalState(map);
|
---|
26 |
|
---|
27 | const {
|
---|
28 | connectionState: {connections,setConnections},
|
---|
29 | handlers: {addConnection,removeConnection}
|
---|
30 | } = useConnections(map,shapeInfo,setShapeInfo)
|
---|
31 |
|
---|
32 |
|
---|
33 | useModalEvent((event) => {
|
---|
34 | const shape = event.detail.room;
|
---|
35 | setShape(shape);
|
---|
36 | setShapeInfo({
|
---|
37 | ...shape.info,
|
---|
38 | selectedPin: ""
|
---|
39 |
|
---|
40 | })
|
---|
41 | const connections = shape.info.selectedPins || [];
|
---|
42 | setConnections(connections);
|
---|
43 | setIsOpen(true);
|
---|
44 | console.log(connections, "Loaded pins on modal open");
|
---|
45 | },"openEntranceModalEvent")
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | return (
|
---|
50 | <Modal isOpen={isOpen} toggleModal={toggleModal} title={"Enter Entrance Details"}>
|
---|
51 | <ModalNameField shapeInfo={shapeInfo} updateModalData={updateModalData}/>
|
---|
52 | <ModalSelectRoom shapeInfo={shapeInfo} availableRooms={ShapeQuery.findAllByTypeAndFloor(shape?.floorNum,"Room")} updateModalData={updateModalData}/>
|
---|
53 | <ModalSelectConnections2
|
---|
54 | availableShapes={ShapeQuery.findAllByType("InfoPin","Entrance")} // najubo ke e entrance samo so room da mozit
|
---|
55 | addConnection={addConnection}
|
---|
56 | updateModalData={updateModalData}
|
---|
57 | shapeInfo={shapeInfo}
|
---|
58 | />
|
---|
59 | <ModalDisplayConnections connections={connections} removePinFromList={removeConnection}/>
|
---|
60 | <ModalDescriptionField shapeInfo={shapeInfo} updateModalData={updateModalData}/>
|
---|
61 | <ModalMainEntranceCheckbox shapeInfo={shapeInfo} updateModalData={updateModalData}></ModalMainEntranceCheckbox>
|
---|
62 | <ModalSaveButton saveDetails={saveDetails}/>
|
---|
63 | </Modal>
|
---|
64 | );
|
---|
65 | }
|
---|
66 |
|
---|
67 | EntranceModal.propTypes = {
|
---|
68 | map: PropTypes.instanceOf(MapBuilder),
|
---|
69 | };
|
---|