|
1 |
| -import { Link, Route, BrowserRouter as Router, Switch } from 'react-router-dom'; |
2 | 1 | import React, { useEffect, useRef } from 'react';
|
3 |
| -import { useDispatch, useSelector } from 'react-redux'; |
4 |
| - |
| 2 | +import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'; |
5 | 3 | import Box from '@mui/material/Box';
|
6 | 4 | import { Component } from '../../interfaces/Interfaces';
|
7 | 5 | import ReactDOMServer from 'react-dom/server';
|
8 |
| -import { RootState } from '../../redux/store'; |
| 6 | +import { useDispatch, useSelector } from 'react-redux'; |
9 | 7 | import { changeFocus } from '../../redux/reducers/slice/appStateSlice';
|
| 8 | +import { RootState } from '../../redux/store'; |
10 | 9 |
|
11 | 10 | // DemoRender is the full sandbox demo of our user's custom built React components. DemoRender references the design specifications stored in state to construct
|
12 | 11 | // real react components that utilize hot module reloading to depict the user's prototype application.
|
@@ -54,21 +53,16 @@ const DemoRender = (): JSX.Element => {
|
54 | 53 | `;
|
55 | 54 |
|
56 | 55 | //Switch between components when clicking on a link in the live render
|
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 |
| - |
| 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 | + }; |
72 | 66 |
|
73 | 67 | // 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
|
74 | 68 | // Material UI is utilized to incorporate the apporpriate tags with specific configuration designs as necessitated by HTML standards.
|
|
0 commit comments