Skip to content

Commit

Permalink
front: fix nge component for reactive properties
Browse files Browse the repository at this point in the history
Signed-off-by: Benoit Simard <[email protected]>
  • Loading branch information
sim51 committed Dec 6, 2024
1 parent 099f476 commit d8d6bd1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions front/src/applications/operationalStudies/components/NGE/NGE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ const NGE = ({ dto, onOperation }: NGEProps) => {
const ngeRoot = frame.contentDocument!.createElement('sbb-root') as NGEElement;
frame.contentDocument!.body.appendChild(ngeRoot);
setNgeRootElement(ngeRoot);

// listens to create, update and delete operations
ngeRoot.addEventListener('operation', (event: Event) => {
const customEvent = event as CustomEvent;
const op = customEvent.detail as NGEEvent;

if (onOperation) onOperation(op, ngeRoot.netzgrafikDto);
});
};

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

useEffect(() => {
if (ngeRootElement && onOperation) {
const fnOpListener = (event: Event) => {
const customEvent = event as CustomEvent;
const op = customEvent.detail as NGEEvent;
if (onOperation) onOperation(op, ngeRootElement.netzgrafikDto);
};
ngeRootElement.addEventListener('operation', fnOpListener);
return () => {
ngeRootElement.removeEventListener('operation', fnOpListener);
};
}
return () => {};
}, [onOperation, ngeRootElement]);

return <iframe ref={frameRef} srcDoc={frameSrc} title="NGE" className="nge-iframe-container" />;
};

Expand Down

0 comments on commit d8d6bd1

Please sign in to comment.