Skip to content
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

make compiler interchangable, closes #357 #385

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
REACT_APP_COMPILER_URL=https://compile.sensebox.de
REACT_APP_INITIAL_COMPILER_URL=https://compiler.sensebox.de

REACT_APP_BOARD=sensebox-mcu
REACT_APP_BLOCKLY_API=https://api.blockly.sensebox.de

Expand Down
4 changes: 4 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "@mui/material/styles";

import Content from "./components/Content";
import { setCompiler } from "./actions/generalActions";

const theme = createTheme({
palette: {
Expand All @@ -36,6 +37,9 @@ const theme = createTheme({
class App extends Component {
componentDidMount() {
store.dispatch(loadUser());
// set initial compiler
console.log("compiler", process.env.REACT_APP_INITIAL_COMPILER_URL)
store.dispatch(setCompiler(process.env.REACT_APP_INITIAL_COMPILER_URL));
}

render() {
Expand Down
1 change: 1 addition & 0 deletions src/components/Blockly/msg/de/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export const UI = {
"Geben die URL des Compilers ein, den du verwenden möchten. Die Standard-URL ist: https://compiler.sensebox.de",
settings_compiler_helperText:
"Die URL muss mit https:// oder http:// beginnen",
settings_compiler_readOnly: "Compiler URL ändern",

/**
* 404
Expand Down
1 change: 1 addition & 0 deletions src/components/Blockly/msg/en/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export const UI = {
settings_compiler_text:
"Enter the URL of the compiler you want to use. The default compiler is: https://compiler.sensebox.de",
settings_compiler_helperText: "Die URL must start https:// or http://",
settings_compiler_readOnly: "Change compiler URL",

/**
* 404
Expand Down
4 changes: 2 additions & 2 deletions src/components/CodeEditor/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const CodeEditor = (props) => {
: "sensebox-esp32s2",
sketch: editorRef.current.getValue(),
};
fetch(`${process.env.REACT_APP_COMPILER_URL}/compile`, {
fetch(`${this.props.selectedCompiler}/compile`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
Expand All @@ -53,7 +53,7 @@ const CodeEditor = (props) => {
//setId(result);
const filename = "sketch";
window.open(
`${process.env.REACT_APP_COMPILER_URL}/download?id=${result}&board=${
`${this.props.selectedCompiler}/download?id=${result}&board=${
store.getState().board.board === "mcu"
? "sensebox-mcu"
: "sensebox-esp32s2"
Expand Down
67 changes: 37 additions & 30 deletions src/components/Settings/CompilerSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,52 @@ class CompilerSelector extends Component {
// Ensure that Blockly.setLocale is adopted in the component.
// Otherwise, the text will not be displayed until the next update of the component.
this.forceUpdate();

}


changeStatus = () => {
this.setState({ readOnly: !this.state.readOnly });
};

render() {
return (
<div>
<Typography style={{ fontWeight: "bold" }}>
{Blockly.Msg.settings_compiler}
</Typography>
<FormHelperText
style={{
color: "black",
lineHeight: 1.3,
marginBottom: "8px",
}}
>
{Blockly.Msg.settings_compiler_text}
</FormHelperText>
<FormControl variant="standard">
<TextField
id="outlined-helperText"
label="Helper text"
helperText={Blockly.Msg.settings_compiler_helperText}
onChange={(e) => this.props.setCompiler(e.target.value)}
value={this.props.selectedCompiler}
InputProps={{
readOnly: !this.state.readOnly,
}}
/>
<FormControlLabel
control={<Checkbox defaultChecked />}
checked={this.state.readOnly}
onChange={this.changeStatus}
label="Change URL"
/>
</FormControl>
<Typography style={{ fontWeight: "bold" }}>
{Blockly.Msg.settings_compiler}
</Typography>
<FormHelperText
style={{
color: "black",
lineHeight: 1.3,
marginBottom: "8px",
}}
>
{Blockly.Msg.settings_compiler_text}
</FormHelperText>
<FormControl variant="standard">
<FormControlLabel
control={<Checkbox defaultChecked />}
checked={this.state.readOnly}
onChange={this.changeStatus}
label={Blockly.Msg.settings_compiler_readOnly}
/>
<TextField
id="outlined-helperText"
label="Helper text"
helperText={Blockly.Msg.settings_compiler_helperText}
onChange={(e) => this.props.setCompiler(e.target.value)}
value={this.props.selectedCompiler}
InputProps={{
readOnly: !this.state.readOnly,
}}
style={{
backgroundColor: !this.state.readOnly ? "#f0f0f0" : "white",
color: this.state.readOnly ? "gray" : "black",
borderRadius: "5px",
}}
/>
</FormControl>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/generalReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const initialPlatform = () => {
};

const initialCompiler = () => {
return process.env.REACT_APP_COMPILER_URL;
return process.env.INITIAL_COMPILER_URL;
};

const initialSounds = () => {
Expand Down