Skip to content

Commit c13b177

Browse files
committed
front: fix nge component for reactive properties
Signed-off-by: Benoit Simard <contact@bsimard.com>
1 parent 0f5046d commit c13b177

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
@@ -52,14 +52,6 @@ const NGE = ({ dto, onOperation }: NGEProps) => {
5252
const ngeRoot = frame.contentDocument!.createElement('sbb-root') as NGEElement;
5353
frame.contentDocument!.body.appendChild(ngeRoot);
5454
setNgeRootElement(ngeRoot);
55-
56-
// listens to create, update and delete operations
57-
ngeRoot.addEventListener('operation', (event: Event) => {
58-
const customEvent = event as CustomEvent;
59-
const op = customEvent.detail as NGEEvent;
60-
61-
if (onOperation) onOperation(op, ngeRoot.netzgrafikDto);
62-
});
6355
};
6456

6557
frame.addEventListener('load', handleFrameLoad);
@@ -75,6 +67,21 @@ const NGE = ({ dto, onOperation }: NGEProps) => {
7567
}
7668
}, [dto, ngeRootElement]);
7769

70+
useEffect(() => {
71+
if (ngeRootElement && onOperation) {
72+
const fnOpListener = (event: Event) => {
73+
const customEvent = event as CustomEvent;
74+
const op = customEvent.detail as NGEEvent;
75+
if (onOperation) onOperation(op, ngeRootElement.netzgrafikDto);
76+
};
77+
ngeRootElement.addEventListener('operation', fnOpListener);
78+
return () => {
79+
ngeRootElement.removeEventListener('operation', fnOpListener);
80+
};
81+
}
82+
return () => {};
83+
}, [onOperation, ngeRootElement]);
84+
7885
return <iframe ref={frameRef} srcDoc={frameSrc} title="NGE" className="nge-iframe-container" />;
7986
};
8087

0 commit comments

Comments
 (0)