Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit f72c49e

Browse files
committed
Additional refactoring
1 parent e4a575d commit f72c49e

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

src/view/components/clue/ClueImage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as React from "react";
55
import { VIEW_STATE } from "../../constants";
6-
import CONSTANTS, { MICROBIT_BUTTON_STYLING_CLASSES } from "../../constants";
6+
import CONSTANTS, { BUTTON_STYLING_CLASSES } from "../../constants";
77
import { ViewStateContext } from "../../context";
88
import "../../styles/Microbit.css";
99
import { IRefObject, ClueSvg } from "./Clue_svg";
@@ -96,12 +96,12 @@ export class ClueImage extends React.Component<IProps, {}> {
9696
if (isActive) {
9797
button.children[0].setAttribute(
9898
"class",
99-
MICROBIT_BUTTON_STYLING_CLASSES.KEYPRESSED
99+
BUTTON_STYLING_CLASSES.KEYPRESSED
100100
);
101101
} else {
102102
button.children[0].setAttribute(
103103
"class",
104-
MICROBIT_BUTTON_STYLING_CLASSES.DEFAULT
104+
BUTTON_STYLING_CLASSES.DEFAULT
105105
);
106106
}
107107
button.setAttribute("pressed", `${isActive}`);

src/view/components/clue/ClueSimulator.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface IState {
2525
play_button: boolean;
2626
selected_file: string;
2727
clue: IClueState;
28+
currently_selected_file: string;
2829
}
2930

3031
interface IClueState {
@@ -40,7 +41,8 @@ export class ClueSimulator extends React.Component<any, IState> {
4041
play_button: false,
4142
selected_file: "",
4243
active_editors: [],
43-
running_file: "",
44+
running_file: undefined,
45+
currently_selected_file: "",
4446
};
4547
this.onKeyEvent = this.onKeyEvent.bind(this);
4648
}
@@ -63,8 +65,10 @@ export class ClueSimulator extends React.Component<any, IState> {
6365
});
6466
break;
6567
case "activate-play":
68+
const newRunningFile = this.state.currently_selected_file;
6669
this.setState({
6770
play_button: !this.state.play_button,
71+
running_file: newRunningFile,
6872
});
6973
break;
7074
case "visible-editors":
@@ -73,9 +77,17 @@ export class ClueSimulator extends React.Component<any, IState> {
7377
});
7478
break;
7579
case "current-file":
76-
this.setState({
77-
running_file: message.state.running_file,
78-
});
80+
if (this.state.play_button) {
81+
this.setState({
82+
currently_selected_file: message.state.running_file,
83+
});
84+
} else {
85+
this.setState({
86+
running_file: message.state.running_file,
87+
currently_selected_file: message.state.running_file,
88+
});
89+
}
90+
7991
break;
8092
}
8193
};
@@ -92,15 +104,11 @@ export class ClueSimulator extends React.Component<any, IState> {
92104
return (
93105
<div className="simulator">
94106
<div className="file-selector">
95-
<Dropdown
96-
label={"file-dropdown"}
97-
styleLabel={"dropdown"}
98-
lastChosen={this.state.running_file}
99-
width={300}
100-
textOptions={this.state.active_editors}
101-
onBlur={this.onSelectFile}
102-
/>
107+
{this.state.running_file && this.state.play_button
108+
? CONSTANTS.CURRENTLY_RUNNING(this.state.running_file)
109+
: CONSTANTS.FILES_PLACEHOLDER}
103110
</div>
111+
104112
<div className="microbit-container">
105113
<ClueImage
106114
ref={this.imageRef}

src/view/components/clue/Clue_svg.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,10 @@ export class ClueSvg extends React.Component<IProps, {}> {
716716

717717
<image
718718
ref={this.displayRef}
719-
x={152}
720-
y={80}
721-
width={198}
722-
height={200}
719+
x={122}
720+
y={50}
721+
width={268}
722+
height={260}
723723
style={{
724724
fill: "rgb(30,30,30)",
725725
}}

src/view/components/microbit/MicrobitImage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as React from "react";
55
import { VIEW_STATE } from "../../constants";
6-
import CONSTANTS, { MICROBIT_BUTTON_STYLING_CLASSES } from "../../constants";
6+
import CONSTANTS, { BUTTON_STYLING_CLASSES } from "../../constants";
77
import { ViewStateContext } from "../../context";
88
import "../../styles/Microbit.css";
99
import { IRefObject, MicrobitSvg } from "./Microbit_svg";
@@ -93,12 +93,12 @@ export class MicrobitImage extends React.Component<IProps, {}> {
9393
if (isActive) {
9494
button.children[0].setAttribute(
9595
"class",
96-
MICROBIT_BUTTON_STYLING_CLASSES.KEYPRESSED
96+
BUTTON_STYLING_CLASSES.KEYPRESSED
9797
);
9898
} else {
9999
button.children[0].setAttribute(
100100
"class",
101-
MICROBIT_BUTTON_STYLING_CLASSES.DEFAULT
101+
BUTTON_STYLING_CLASSES.DEFAULT
102102
);
103103
}
104104
button.setAttribute("pressed", `${isActive}`);

src/view/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const AB_BUTTONS_KEYS = {
5252
BTN_B: "BTN_B",
5353
BTN_AB: "BTN_AB",
5454
};
55-
export const MICROBIT_BUTTON_STYLING_CLASSES = {
55+
export const BUTTON_STYLING_CLASSES = {
5656
DEFAULT: "sim-button-outer",
5757
KEYPRESSED: "sim-button-key-press",
5858
};

0 commit comments

Comments
 (0)