Skip to content

Commit d25a58e

Browse files
committed
update dependences and demo error
1 parent 31d456d commit d25a58e

File tree

3 files changed

+2159
-2931
lines changed

3 files changed

+2159
-2931
lines changed

app/src/components/main/DemoRender.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { Link, Route, BrowserRouter as Router, Switch } from 'react-router-dom';
12
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+
35
import Box from '@mui/material/Box';
46
import { Component } from '../../interfaces/Interfaces';
57
import ReactDOMServer from 'react-dom/server';
6-
import { useDispatch, useSelector } from 'react-redux';
7-
import { changeFocus } from '../../redux/reducers/slice/appStateSlice';
88
import { RootState } from '../../redux/store';
9+
import { changeFocus } from '../../redux/reducers/slice/appStateSlice';
910

1011
// DemoRender is the full sandbox demo of our user's custom built React components. DemoRender references the design specifications stored in state to construct
1112
// real react components that utilize hot module reloading to depict the user's prototype application.
@@ -53,16 +54,21 @@ const DemoRender = (): JSX.Element => {
5354
`;
5455

5556
//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+
6672

6773
// 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
6874
// Material UI is utilized to incorporate the apporpriate tags with specific configuration designs as necessitated by HTML standards.

0 commit comments

Comments
 (0)