Skip to content

Commit c19aef2

Browse files
committed
previewIndex: update to TS, no-verify
1 parent 730eb31 commit c19aef2

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

client/modules/Preview/previewIndex.jsx renamed to client/modules/Preview/previewIndex.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ import { filesReducer, setFiles } from './filesReducer';
1111
import EmbedFrame from './EmbedFrame';
1212
import { getConfig } from '../../utils/getConfig';
1313
import { initialState } from '../IDE/reducers/files';
14+
import { File } from './filesReducer'; // Import File interface
1415

1516
const 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+
2130
const 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

Comments
 (0)