-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathWebComponentLoader.js
More file actions
34 lines (28 loc) · 945 Bytes
/
Copy pathWebComponentLoader.js
File metadata and controls
34 lines (28 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux'
import { setProject, setProjectLoaded, setSenseHatAlwaysEnabled } from '../../Editor/EditorSlice';
import WebComponentProject from '../Project/WebComponentProject';
const ProjectComponentLoader = (props) => {
const projectLoaded = useSelector((state) => state.editor.projectLoaded);
const { code, sense_hat_always_enabled } = props;
const dispatch = useDispatch()
useEffect(() => {
const proj = {
type: 'python',
components: [{ name: 'main', extension: 'py', content: code }]
}
dispatch(setSenseHatAlwaysEnabled(typeof sense_hat_always_enabled !== 'undefined'))
dispatch(setProject(proj))
dispatch(setProjectLoaded(true))
}, []);
return projectLoaded === true ? (
<>
<WebComponentProject />
</>
) : (
<>
<p>Loading</p>
</>
);
};
export default ProjectComponentLoader;