Skip to content

Commit 3a5ebb2

Browse files
author
Conor
committed
tidy up unused files, use redux for endpoint
1 parent ad2d0b0 commit 3a5ebb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+39
-2275
lines changed

.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
REACT_APP_AUTHENTICATION_CLIENT_ID='editor-dev'
2-
REACT_APP_AUTHENTICATION_URL='http://localhost:9001'
32
REACT_APP_SENTRY_DSN=''
43
REACT_APP_SENTRY_ENV='local'
54
PUBLIC_URL='http://localhost:3011'
65
ASSETS_URL='http://localhost:3011'
7-
REACT_APP_API_ENDPOINT='http://localhost:3009'
86
REACT_APP_GOOGLE_TAG_MANAGER_ID=''
97
REACT_APP_PLAUSIBLE_DATA_DOMAIN=''
108
REACT_APP_PLAUSIBLE_SOURCE=''

src/app/store.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import InstructionsReducer from "../redux/InstructionsSlice";
44
import { reducer, loadUser } from "redux-oidc";
55
import UserManager from "../utils/userManager";
66

7-
const userManager = UserManager({ reactAppAuthenticationUrl: "TODORAAU" });
7+
// TODO - not used but keeping this in preparation for using
8+
// src/components/Editor/ImageUploadButton/ImageUploadButton.jsx
9+
const userManager = UserManager({ reactAppAuthenticationUrl: "TODO" });
810
const store = configureStore({
911
reducer: {
1012
editor: EditorReducer,

src/components/DownloadButton/DownloadButton.jsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { toSnakeCase } from "js-convert-case";
44
import JSZip from "jszip";
55
import JSZipUtils from "jszip-utils";
66
import { useTranslation } from "react-i18next";
7-
import { useDispatch, useSelector } from "react-redux";
7+
import { useSelector } from "react-redux";
88
import PropTypes from "prop-types";
99

1010
import DesignSystemButton from "../DesignSystemButton/DesignSystemButton";
11-
import { closeLoginToSaveModal } from "../../redux/EditorSlice";
1211

1312
const DownloadButton = (props) => {
1413
const {
@@ -20,10 +19,6 @@ const DownloadButton = (props) => {
2019
} = props;
2120
const { t } = useTranslation();
2221
const project = useSelector((state) => state.editor.project);
23-
const loginToSaveModalShowing = useSelector(
24-
(state) => state.editor.loginToSaveModalShowing
25-
);
26-
const dispatch = useDispatch();
2722

2823
const urlToPromise = (url) => {
2924
return new Promise(function (resolve, reject) {
@@ -42,9 +37,6 @@ const DownloadButton = (props) => {
4237
window.plausible("Download");
4338
}
4439

45-
if (loginToSaveModalShowing) {
46-
dispatch(closeLoginToSaveModal());
47-
}
4840
const zip = new JSZip();
4941

5042
project.components.forEach((file) => {

src/components/DownloadButton/DownloadButton.test.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import DownloadButton from "./DownloadButton";
66
import FileSaver from "file-saver";
77
import JSZip from "jszip";
88
import JSZipUtils from "jszip-utils";
9-
import { closeLoginToSaveModal } from "../../redux/EditorSlice";
109

1110
jest.mock("file-saver");
1211
jest.mock("jszip");
@@ -124,27 +123,3 @@ describe("Downloading project with no name set", () => {
124123
);
125124
});
126125
});
127-
128-
test("If login to save modal open, closes it when download clicked", () => {
129-
JSZip.mockClear();
130-
const middlewares = [];
131-
const mockStore = configureStore(middlewares);
132-
const initialState = {
133-
editor: {
134-
project: {
135-
components: [],
136-
image_list: [],
137-
},
138-
loginToSaveModalShowing: true,
139-
},
140-
};
141-
const store = mockStore(initialState);
142-
render(
143-
<Provider store={store}>
144-
<DownloadButton buttonText="Download" Icon={() => {}} />
145-
</Provider>,
146-
);
147-
const downloadButton = screen.queryByText("Download").parentElement;
148-
fireEvent.click(downloadButton);
149-
expect(store.getActions()).toEqual([closeLoginToSaveModal()]);
150-
});

src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import OutputViewToggle from "../OutputViewToggle";
1818
import { SettingsContext } from "../../../../../utils/settings";
1919
import RunnerControls from "../../../../RunButton/RunnerControls";
2020

21-
const { createError } = ApiCallHandler({ reactAppApiEndpoint: "TODORAAE" });
22-
2321
const getWorkerURL = (url) => {
2422
const content = `
2523
/* global PyodideWorker */
@@ -49,6 +47,7 @@ const PyodideRunner = (props) => {
4947
const userId = user?.profile?.user;
5048
const isSplitView = useSelector((s) => s.editor.isSplitView);
5149
const isEmbedded = useSelector((s) => s.editor.isEmbedded);
50+
const reactAppApiEndpoint = useSelector((s) => s.editor.reactAppApiEndpoint);
5251
const codeRunTriggered = useSelector((s) => s.editor.codeRunTriggered);
5352
const codeRunStopped = useSelector((s) => s.editor.codeRunStopped);
5453
const output = useRef();
@@ -85,7 +84,7 @@ const PyodideRunner = (props) => {
8584
data.line,
8685
data.mistake,
8786
data.type,
88-
data.info,
87+
data.info
8988
);
9089
break;
9190
case "handleVisual":
@@ -182,6 +181,9 @@ const PyodideRunner = (props) => {
182181
errorMessage += `:\n${mistake}`;
183182
}
184183

184+
const { createError } = ApiCallHandler({
185+
reactAppApiEndpoint,
186+
});
185187
createError(projectIdentifier, userId, { errorType: type, errorMessage });
186188
}
187189

@@ -208,8 +210,8 @@ const PyodideRunner = (props) => {
208210
projectImages.map(({ filename, url }) =>
209211
fetch(url)
210212
.then((response) => response.arrayBuffer())
211-
.then((buffer) => writeFile(filename, buffer)),
212-
),
213+
.then((buffer) => writeFile(filename, buffer))
214+
)
213215
);
214216

215217
for (const { name, extension, content } of projectCode) {
@@ -218,7 +220,7 @@ const PyodideRunner = (props) => {
218220

219221
// program is the content of the component with name main and extension py
220222
const program = projectCode.find(
221-
(component) => component.name === "main" && component.extension === "py",
223+
(component) => component.name === "main" && component.extension === "py"
222224
).content;
223225

224226
if (interruptBuffer.current) {

src/components/Editor/Runners/PythonRunner/PythonRunner.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const SKULPT_ONLY_MODULES = [
1616
const PythonRunner = () => {
1717
const project = useSelector((state) => state.editor.project);
1818
const codeRunTriggered = useSelector(
19-
(state) => state.editor.codeRunTriggered,
19+
(state) => state.editor.codeRunTriggered
2020
);
2121
const senseHatAlwaysEnabled = useSelector(
22-
(state) => state.editor.senseHatAlwaysEnabled,
22+
(state) => state.editor.senseHatAlwaysEnabled
2323
);
2424
const [usePyodide, setUsePyodide] = useState(true);
2525
const { t } = useTranslation();
@@ -32,7 +32,7 @@ const PythonRunner = () => {
3232
const getImports = (code) => {
3333
const codeWithoutMultilineStrings = code.replace(
3434
/'''[\s\S]*?'''|"""[\s\S]*?"""/gm,
35-
"",
35+
""
3636
);
3737
const importRegex =
3838
/(?<=^\s*)(from\s+([a-zA-Z0-9_.]+)(\s+import\s+([a-zA-Z0-9_.]+))?)|(?<=^\s*)(import\s+([a-zA-Z0-9_.]+))/gm;
@@ -43,7 +43,7 @@ const PythonRunner = () => {
4343
match
4444
.split(/from|import/)
4545
.filter(Boolean)
46-
.map((s) => s.trim())[0],
46+
.map((s) => s.trim())[0]
4747
)
4848
: [];
4949
if (code.includes(`# ${t("input.comment.py5")}`)) {
@@ -57,7 +57,7 @@ const PythonRunner = () => {
5757
try {
5858
const imports = getImports(component.content);
5959
const hasSkulptOnlyModules = imports.some((name) =>
60-
SKULPT_ONLY_MODULES.includes(name),
60+
SKULPT_ONLY_MODULES.includes(name)
6161
);
6262
if (hasSkulptOnlyModules || senseHatAlwaysEnabled) {
6363
setUsePyodide(false);

src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import RunnerControls from "../../../../RunButton/RunnerControls";
2424
import { MOBILE_MEDIA_QUERY } from "../../../../../utils/mediaQueryBreakpoints";
2525
import classNames from "classnames";
2626

27-
const { createError } = ApiCallHandler({ reactAppApiEndpoint: "TODORAAE" });
28-
2927
const externalLibraries = {
3028
"./pygal/__init__.js": {
3129
path: `${process.env.ASSETS_URL}/shims/pygal/pygal.js`,
@@ -59,20 +57,21 @@ const externalLibraries = {
5957
const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
6058
const projectCode = useSelector((state) => state.editor.project.components);
6159
const mainComponent = projectCode?.find(
62-
(component) => component.name === "main" && component.extension === "py",
60+
(component) => component.name === "main" && component.extension === "py"
6361
);
6462
const projectIdentifier = useSelector(
65-
(state) => state.editor.project.identifier,
63+
(state) => state.editor.project.identifier
6664
);
6765
const user = useSelector((state) => state.auth.user);
6866
const isSplitView = useSelector((state) => state.editor.isSplitView);
6967
const isEmbedded = useSelector((state) => state.editor.isEmbedded);
7068
const isOutputOnly = useSelector((state) => state.editor.isOutputOnly);
7169
const codeRunTriggered = useSelector(
72-
(state) => state.editor.codeRunTriggered,
70+
(state) => state.editor.codeRunTriggered
7371
);
7472
const codeRunStopped = useSelector((state) => state.editor.codeRunStopped);
7573
const drawTriggered = useSelector((state) => state.editor.drawTriggered);
74+
const reactAppApiEndpoint = useSelector((s) => s.editor.reactAppApiEndpoint);
7675
const output = useRef();
7776
const dispatch = useDispatch();
7877
const { t } = useTranslation();
@@ -191,7 +190,7 @@ const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
191190
.then((code) => {
192191
if (!code) {
193192
throw new Sk.builtin.ImportError(
194-
"Failed to load remote module",
193+
"Failed to load remote module"
195194
);
196195
}
197196
externalLibraries[library].code = code;
@@ -200,7 +199,7 @@ const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
200199
function mapUrlToPromise(path) {
201200
// If the script is already in the DOM don't add it again.
202201
const existingScriptElement = document.querySelector(
203-
`script[src="${path}"]`,
202+
`script[src="${path}"]`
204203
);
205204
if (!existingScriptElement) {
206205
return new Promise(function (resolve, _reject) {
@@ -222,11 +221,11 @@ const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
222221
(p, url) => {
223222
return p.then(() => mapUrlToPromise(url));
224223
},
225-
Promise.resolve(),
224+
Promise.resolve()
226225
); // initial
227226
} else {
228227
promise = Promise.all(
229-
(externalLibraryInfo.dependencies || []).map(mapUrlToPromise),
228+
(externalLibraryInfo.dependencies || []).map(mapUrlToPromise)
230229
);
231230
}
232231

@@ -236,10 +235,10 @@ const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
236235
})
237236
.catch(function () {
238237
throw new Sk.builtin.ImportError(
239-
"Failed to load dependencies required",
238+
"Failed to load dependencies required"
240239
);
241240
});
242-
}),
241+
})
243242
)
244243
);
245244
}
@@ -316,6 +315,8 @@ const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
316315
userId = user.profile?.user;
317316
}
318317

318+
const { createError } = ApiCallHandler({ reactAppApiEndpoint });
319+
319320
errorMessage = `${errorType}: ${errorDescription} on line ${lineNumber} of ${fileName}${
320321
explanation ? `. ${explanation}` : ""
321322
}`;
@@ -357,7 +358,7 @@ const SkulptRunner = ({ active, outputPanels = ["text", "visual"] }) => {
357358
if (prog.includes(`# ${t("input.comment.py5")}`)) {
358359
prog = prog.replace(
359360
`# ${t("input.comment.py5")}`,
360-
"from py5_imported_mode import *",
361+
"from py5_imported_mode import *"
361362
);
362363

363364
if (!prog.match(/(\nrun_sketch)/)) {

src/components/Login/LoginButton.jsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)