@@ -11,13 +11,22 @@ import { filesReducer, setFiles } from './filesReducer';
1111import EmbedFrame from './EmbedFrame' ;
1212import { getConfig } from '../../utils/getConfig' ;
1313import { initialState } from '../IDE/reducers/files' ;
14+ import { File } from './filesReducer' ; // Import File interface
1415
1516const GlobalStyle = createGlobalStyle `
1617 body {
1718 margin: 0;
1819 }
1920` ;
2021
22+ interface AppState {
23+ files : File [ ] ;
24+ isPlaying : boolean ;
25+ basePath : string ;
26+ textOutput : boolean ;
27+ gridOutput : boolean ;
28+ }
29+
2130const App = ( ) => {
2231 const [ state , dispatch ] = useReducer ( filesReducer , [ ] , initialState ) ;
2332 const [ isPlaying , setIsPlaying ] = useState ( false ) ;
@@ -26,14 +35,16 @@ const App = () => {
2635 const [ gridOutput , setGridOutput ] = useState ( false ) ;
2736 registerFrame ( window . parent , getConfig ( 'EDITOR_URL' ) ) ;
2837
29- function handleMessageEvent ( message ) {
38+ function handleMessageEvent ( message : { type : string ; payload ?: any } ) {
3039 const { type, payload } = message ;
3140 switch ( type ) {
3241 case MessageTypes . SKETCH :
33- dispatch ( setFiles ( payload . files ) ) ;
34- setBasePath ( payload . basePath ) ;
35- setTextOutput ( payload . textOutput ) ;
36- setGridOutput ( payload . gridOutput ) ;
42+ if ( payload ) {
43+ dispatch ( setFiles ( payload . files ) ) ;
44+ setBasePath ( payload . basePath ) ;
45+ setTextOutput ( payload . textOutput ) ;
46+ setGridOutput ( payload . gridOutput ) ;
47+ }
3748 break ;
3849 case MessageTypes . START :
3950 setIsPlaying ( true ) ;
@@ -45,14 +56,16 @@ const App = () => {
4556 dispatchMessage ( { type : MessageTypes . REGISTER } ) ;
4657 break ;
4758 case MessageTypes . EXECUTE :
48- dispatchMessage ( payload ) ;
59+ if ( payload ) {
60+ dispatchMessage ( payload ) ;
61+ }
4962 break ;
5063 default :
5164 break ;
5265 }
5366 }
5467
55- function addCacheBustingToAssets ( files ) {
68+ function addCacheBustingToAssets ( files : File [ ] ) : File [ ] {
5669 const timestamp = new Date ( ) . getTime ( ) ;
5770 return files . map ( ( file ) => {
5871 if ( file . url && ! file . url . endsWith ( 'obj' ) && ! file . url . endsWith ( 'stl' ) ) {
0 commit comments