main
Last change
on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago |
Pred finalna verzija
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import {useState} from "react";
|
---|
2 | import triggerMapSave from "../../../scripts/util/triggerMapSave.js";
|
---|
3 |
|
---|
4 | export default function useModalState(map) {
|
---|
5 | const [isOpen, setIsOpen] = useState(false);
|
---|
6 | const [shape, setShape] = useState(null);
|
---|
7 | const [shapeInfo,setShapeInfo] = useState({});
|
---|
8 |
|
---|
9 |
|
---|
10 | const toggleModal = () => {
|
---|
11 | if (isOpen) {
|
---|
12 | shape.setInfo(shapeInfo);
|
---|
13 | map.updateRoomNames();
|
---|
14 | triggerMapSave();
|
---|
15 | console.log("SHAPE BEF CLOSE:",shape.info)
|
---|
16 | }
|
---|
17 | setIsOpen(!isOpen);
|
---|
18 | };
|
---|
19 |
|
---|
20 | const updateModalData = (e) => {
|
---|
21 | const {name, value, type, checked} = e.target;
|
---|
22 | setShapeInfo(prevShapeInfo => ({
|
---|
23 | ...prevShapeInfo,
|
---|
24 | [name]: type === "checkbox" ? checked : value
|
---|
25 | }
|
---|
26 | ))
|
---|
27 | console.log("SHAPE INFO UPDATE",shape.info)
|
---|
28 | };
|
---|
29 |
|
---|
30 | const saveDetails = () => {
|
---|
31 | if (shape) {
|
---|
32 | toggleModal();
|
---|
33 | }
|
---|
34 | };
|
---|
35 |
|
---|
36 | return {
|
---|
37 | modalState: {isOpen, shapeInfo,setIsOpen, shape, setShape,setShapeInfo},
|
---|
38 | handlers: {toggleModal, updateModalData, saveDetails}
|
---|
39 | };
|
---|
40 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.