Skip to content

Commit 9df76f9

Browse files
committed
WIP: Add Scratch GUI in iframe
1 parent 1eae407 commit 9df76f9

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

src/components/Editor/Project/Project.jsx

+25-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const Project = (props) => {
2525
} = props;
2626
const saving = useSelector((state) => state.editor.saving);
2727
const autosave = useSelector((state) => state.editor.lastSaveAutosave);
28+
const project = useSelector((state) => state.editor.project);
2829

2930
useEffect(() => {
3031
if (saving === "success" && autosave === false) {
@@ -52,6 +53,8 @@ const Project = (props) => {
5253
setLoading(false);
5354
}, []);
5455

56+
const iframeSrc = "https://scratch-editor.pages.dev/";
57+
5558
return (
5659
<div className="proj" data-testid="project">
5760
<div
@@ -64,18 +67,28 @@ const Project = (props) => {
6467
{withProjectbar && <ProjectBar nameEditable={nameEditable} />}
6568
{!loading && (
6669
<div className="proj-editor-wrapper">
67-
<ResizableWithHandle
68-
data-testid="proj-editor-container"
69-
className="proj-editor-container"
70-
defaultWidth={defaultWidth}
71-
defaultHeight={defaultHeight}
72-
handleDirection={handleDirection}
73-
minWidth="25%"
74-
maxWidth={maxWidth}
75-
>
76-
<EditorInput />
77-
</ResizableWithHandle>
78-
<Output />
70+
{project.project_type === "scratch" ? (
71+
<iframe
72+
src={iframeSrc}
73+
style={{ width: "100%", border: "0px" }}
74+
title="scratch"
75+
></iframe>
76+
) : (
77+
<>
78+
<ResizableWithHandle
79+
data-testid="proj-editor-container"
80+
className="proj-editor-container"
81+
defaultWidth={defaultWidth}
82+
defaultHeight={defaultHeight}
83+
handleDirection={handleDirection}
84+
minWidth="25%"
85+
maxWidth={maxWidth}
86+
>
87+
<EditorInput />
88+
</ResizableWithHandle>
89+
<Output />
90+
</>
91+
)}
7992
</div>
8093
)}
8194
</div>

src/hooks/useProject.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { useRef, useEffect, useState } from "react";
33
import { useDispatch, useSelector } from "react-redux";
44
import { syncProject, setProject } from "../redux/EditorSlice";
5-
import { defaultPythonProject } from "../utils/defaultProjects";
5+
import { defaultScratchProject } from "../utils/defaultProjects";
66
import { useTranslation } from "react-i18next";
77

88
export const useProject = ({
@@ -87,7 +87,7 @@ export const useProject = ({
8787
return;
8888
}
8989

90-
const data = defaultPythonProject;
90+
const data = defaultScratchProject;
9191
dispatch(setProject(data));
9292
}
9393
}, [

src/hooks/useProject.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import configureStore from "redux-mock-store";
44

55
import { useProject } from "./useProject";
66
import { syncProject, setProject } from "../redux/EditorSlice";
7-
import { defaultPythonProject } from "../utils/defaultProjects";
7+
import { defaultScratchProject } from "../utils/defaultProjects";
88

99
jest.mock("react-redux", () => ({
1010
...jest.requireActual("react-redux"),
@@ -53,9 +53,9 @@ describe("When not embedded", () => {
5353
wrapper = ({ children }) => <Provider store={store}>{children}</Provider>;
5454
});
5555

56-
test("If no identifier uses default python project", () => {
56+
test("If no identifier uses default Scratch project", () => {
5757
renderHook(() => useProject({}), { wrapper });
58-
expect(setProject).toHaveBeenCalledWith(defaultPythonProject);
58+
expect(setProject).toHaveBeenCalledWith(defaultScratchProject);
5959
});
6060

6161
test("If cached project matches identifer uses cached project", () => {

src/utils/defaultProjects.js

+7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ export const defaultHtmlProject = {
2121
],
2222
};
2323

24+
export const defaultScratchProject = {
25+
project_type: "scratch",
26+
name: i18n.t("project.untitled"),
27+
components: [{ extension: "sb3", name: "main", content: "" }],
28+
};
29+
2430
export const DEFAULT_PROJECTS = {
2531
python: defaultPythonProject,
2632
html: defaultHtmlProject,
33+
scratch: defaultScratchProject,
2734
};

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module.exports = {
106106
"X-Requested-With, content-type, Authorization",
107107
// Pyodide - required for input and code interruption - needed on the host app
108108
"Cross-Origin-Opener-Policy": "same-origin",
109-
"Cross-Origin-Embedder-Policy": "require-corp",
109+
"Cross-Origin-Embedder-Policy": "cross-origin"
110110
},
111111
setupMiddlewares: (middlewares, devServer) => {
112112
devServer.app.use((req, res, next) => {

0 commit comments

Comments
 (0)