Skip to content

Commit

Permalink
WIP: Spike adding Scratch project type
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Jan 8, 2025
1 parent 268c6f6 commit 847c7aa
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"arrowParens": "always"
}
]
}
},
"ignorePatterns": ["src/gui.js"]
}
38 changes: 26 additions & 12 deletions src/components/Editor/Project/Project.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Project = (props) => {
} = props;
const saving = useSelector((state) => state.editor.saving);
const autosave = useSelector((state) => state.editor.lastSaveAutosave);
const project = useSelector((state) => state.editor.project);

useEffect(() => {
if (saving === "success" && autosave === false) {
Expand Down Expand Up @@ -52,6 +53,9 @@ const Project = (props) => {
setLoading(false);
}, []);

const publicUrl = process.env.PUBLIC_URL;
const iframeSrc = `${publicUrl}/scratch-component.html`;

return (
<div className="proj" data-testid="project">
<div
Expand All @@ -64,18 +68,28 @@ const Project = (props) => {
{withProjectbar && <ProjectBar nameEditable={nameEditable} />}
{!loading && (
<div className="proj-editor-wrapper">
<ResizableWithHandle
data-testid="proj-editor-container"
className="proj-editor-container"
defaultWidth={defaultWidth}
defaultHeight={defaultHeight}
handleDirection={handleDirection}
minWidth="25%"
maxWidth={maxWidth}
>
<EditorInput />
</ResizableWithHandle>
<Output />
{project.project_type === "scratch" ? (
<iframe
src={iframeSrc}
style={{ width: "100%", border: "0px" }}
title="scratch"
></iframe>
) : (
<>
<ResizableWithHandle
data-testid="proj-editor-container"
className="proj-editor-container"
defaultWidth={defaultWidth}
defaultHeight={defaultHeight}
handleDirection={handleDirection}
minWidth="25%"
maxWidth={maxWidth}
>
<EditorInput />
</ResizableWithHandle>
<Output />
</>
)}
</div>
)}
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/gui.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/hooks/useProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useRef, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { syncProject, setProject } from "../redux/EditorSlice";
import { defaultPythonProject } from "../utils/defaultProjects";
import { defaultScratchProject } from "../utils/defaultProjects";
import { useTranslation } from "react-i18next";

export const useProject = ({
Expand Down Expand Up @@ -87,7 +87,7 @@ export const useProject = ({
return;
}

const data = defaultPythonProject;
const data = defaultScratchProject;
dispatch(setProject(data));
}
}, [
Expand Down
7 changes: 7 additions & 0 deletions src/scratch-component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
<script defer="defer" src="/gui.js"></script>
</head>
<body>
</body>
</html>
7 changes: 7 additions & 0 deletions src/utils/defaultProjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ export const defaultHtmlProject = {
],
};

export const defaultScratchProject = {
project_type: "scratch",
name: i18n.t("project.untitled"),
components: [{ extension: "sb3", name: "main", content: "" }],
};

export const DEFAULT_PROJECTS = {
python: defaultPythonProject,
html: defaultHtmlProject,
scratch: defaultScratchProject,
};
8 changes: 7 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ module.exports = {
// Pyodide - required for input and code interruption - needed on the host app
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
"Cross-Origin-Resource-Policy": "cross-origin",
},
setupMiddlewares: (middlewares, devServer) => {
devServer.app.use((req, res, next) => {
Expand Down Expand Up @@ -136,8 +137,13 @@ module.exports = {
template: "src/web-component.html",
filename: "web-component.html",
}),
new HtmlWebpackPlugin({
inject: "body",
template: "src/scratch-component.html",
filename: "scratch-component.html",
}),
new CopyWebpackPlugin({
patterns: [{ from: "public", to: "" }],
patterns: [{ from: "public", to: "" }, { from: "src/gui.js", to: "" }],
}),
],
stats: "minimal",
Expand Down

0 comments on commit 847c7aa

Please sign in to comment.