Skip to content

Block-to-text Output only Web Component #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ability to trigger code run outside the web component
  • Loading branch information
loiswells97 committed Jan 12, 2024
commit f9086a88bb343ef7ff4ce8623a64d1162191c293
25 changes: 24 additions & 1 deletion src/containers/WebComponentLoader.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { useEffect, useState } from "react";
import { useSelector, useDispatch } from "react-redux";
import { disableTheming, setSenseHatAlwaysEnabled } from "../redux/EditorSlice";
import {
disableTheming,
setSenseHatAlwaysEnabled,
stopCodeRun,
stopDraw,
triggerCodeRun,
} from "../redux/EditorSlice";
import WebComponentProject from "../components/WebComponentProject/WebComponentProject";
import { useTranslation } from "react-i18next";
import { setInstructions } from "../redux/InstructionsSlice";
Expand Down Expand Up @@ -41,6 +47,23 @@ const WebComponentLoader = (props) => {
? "dark"
: "light";

const [isRunCodeListenerAdded, setIsRunCodeListenerAdded] = useState(false);

const runCode = () => {
dispatch(stopCodeRun());
dispatch(stopDraw());
dispatch(triggerCodeRun());
};

// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => {
if (outputOnly && !isRunCodeListenerAdded) {
document.removeEventListener("outputOnly-runCode", runCode);
document.addEventListener("outputOnly-runCode", runCode);
setIsRunCodeListenerAdded(true);
}
});

useEffect(() => {
if (theme) {
dispatch(disableTheming());
Expand Down