|
| 1 | +import { Link, Route, BrowserRouter as Router, Switch } from 'react-router-dom'; |
1 | 2 | import React, { useEffect, useRef } from 'react';
|
2 |
| -import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'; |
| 3 | +import { useDispatch, useSelector } from 'react-redux'; |
| 4 | + |
3 | 5 | import Box from '@mui/material/Box';
|
4 | 6 | import { Component } from '../../interfaces/Interfaces';
|
5 | 7 | import ReactDOMServer from 'react-dom/server';
|
6 |
| -import { useDispatch, useSelector } from 'react-redux'; |
7 |
| -import { changeFocus } from '../../redux/reducers/slice/appStateSlice'; |
8 | 8 | import { RootState } from '../../redux/store';
|
| 9 | +import { changeFocus } from '../../redux/reducers/slice/appStateSlice'; |
9 | 10 |
|
10 | 11 | // DemoRender is the full sandbox demo of our user's custom built React components. DemoRender references the design specifications stored in state to construct
|
11 | 12 | // real react components that utilize hot module reloading to depict the user's prototype application.
|
@@ -53,16 +54,21 @@ const DemoRender = (): JSX.Element => {
|
53 | 54 | `;
|
54 | 55 |
|
55 | 56 | //Switch between components when clicking on a link in the live render
|
56 |
| - window.onmessage = (event) => { |
57 |
| - if (event.data === undefined) return; |
58 |
| - const component: string = event.data.data?.split('/').at(-1); |
59 |
| - const componentId = |
60 |
| - component && |
61 |
| - state.components?.find((el) => { |
62 |
| - return el.name.toLowerCase() === component.toLowerCase(); |
63 |
| - }).id; |
64 |
| - componentId && dispatch(changeFocus({ componentId, childId: null })); |
65 |
| - }; |
| 57 | +window.onmessage = (event) => { |
| 58 | + if (event.data === undefined) return; |
| 59 | + |
| 60 | + const data = event.data.data; |
| 61 | + if (typeof data !== 'string') return; // Make sure data is a string |
| 62 | + |
| 63 | + const component: string = data.split('/').at(-1); |
| 64 | + const componentId = |
| 65 | + component && |
| 66 | + state.components?.find((el) => { |
| 67 | + return el.name.toLowerCase() === component.toLowerCase(); |
| 68 | + })?.id; // Use optional chaining for state.components |
| 69 | + componentId && dispatch(changeFocus({ componentId, childId: null })); |
| 70 | +}; |
| 71 | + |
66 | 72 |
|
67 | 73 | // This function is the heart of DemoRender it will take the array of components stored in state and dynamically construct the desired React component for the live demo
|
68 | 74 | // Material UI is utilized to incorporate the apporpriate tags with specific configuration designs as necessitated by HTML standards.
|
|
0 commit comments