Skip to content

Commit b3dfa2f

Browse files
committed
front: fix nge component for reactive properties
Signed-off-by: Benoit Simard <[email protected]>
1 parent ea0cda5 commit b3dfa2f

File tree

1 file changed

+15
-8
lines changed
  • front/src/applications/operationalStudies/components/NGE

1 file changed

+15
-8
lines changed

front/src/applications/operationalStudies/components/NGE/NGE.tsx

+15-8
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ const NGE = ({ dto, onOperation }: NGEProps) => {
5555
const ngeRoot = frame.contentDocument!.createElement('sbb-root') as NGEElement;
5656
frame.contentDocument!.body.appendChild(ngeRoot);
5757
setNgeRootElement(ngeRoot);
58-
59-
// listens to create, update and delete operations
60-
ngeRoot.addEventListener('operation', (event: Event) => {
61-
const customEvent = event as CustomEvent;
62-
const op = customEvent.detail as NGEEvent;
63-
64-
if (onOperation) onOperation(op, ngeRoot.netzgrafikDto);
65-
});
6658
};
6759

6860
frame.addEventListener('load', handleFrameLoad);
@@ -84,6 +76,21 @@ const NGE = ({ dto, onOperation }: NGEProps) => {
8476
}
8577
}, [dto, ngeRootElement]);
8678

79+
useEffect(() => {
80+
if (ngeRootElement && onOperation) {
81+
const fnOpListener = (event: Event) => {
82+
const customEvent = event as CustomEvent;
83+
const op = customEvent.detail as NGEEvent;
84+
if (onOperation) onOperation(op, ngeRootElement.netzgrafikDto);
85+
};
86+
ngeRootElement.addEventListener('operation', fnOpListener);
87+
return () => {
88+
ngeRootElement.removeEventListener('operation', fnOpListener);
89+
};
90+
}
91+
return () => {};
92+
}, [onOperation, ngeRootElement]);
93+
8794
return <iframe ref={frameRef} srcDoc={frameSrc} title="NGE" className="nge-iframe-container" />;
8895
};
8996

0 commit comments

Comments
 (0)