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