Skip to content

Commit

Permalink
Merge pull request #13 from Graham42/react-16
Browse files Browse the repository at this point in the history
Upgrade to React 16
  • Loading branch information
philippotto authored Oct 29, 2017
2 parents 5de3656 + c99eb7f commit 7368e67
Show file tree
Hide file tree
Showing 33 changed files with 416 additions and 328 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- 4.4.0
- lts/*
- stable
install:
- npm install
Expand Down
21 changes: 18 additions & 3 deletions app/scripts/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,28 @@ export default class App extends Component {
</div>
<div className="row">
<div className="col-md-12 col-xs-12">
<a href="http://facebook.com/SheetMusicTutor" target="_blank" className="btn btn-primary">
<a
href="http://facebook.com/SheetMusicTutor"
target="_blank"
rel="noopener noreferrer"
className="btn btn-primary"
>
<i className="fa fa-facebook" />
</a>
<a href="http://twitter.com/SheetMusicTutor" target="_blank" className="btn btn-primary">
<a
href="http://twitter.com/SheetMusicTutor"
target="_blank"
rel="noopener noreferrer"
className="btn btn-primary"
>
<i className="fa fa-twitter" />
</a>
<a href="http://github.com/philippotto/piano-trainer" target="_blank" className="btn btn-primary">
<a
href="http://github.com/philippotto/piano-trainer"
target="_blank"
rel="noopener noreferrer"
className="btn btn-primary"
>
<i className="fa fa-github" />
</a>
</div>
Expand Down
24 changes: 19 additions & 5 deletions app/scripts/services/pitch_statistic_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class PitchStatisticService {
this.stats = localStorage.getItem(localStoragePitchStatsKey);

if (this.stats) {
this.stats = JSON.parse(this.stats).map(this.transformDate).map(StatEvolver.evolveToLatestSchema);
this.stats = JSON.parse(this.stats)
.map(this.transformDate)
.map(StatEvolver.evolveToLatestSchema);
} else {
this.stats = [];
}
Expand All @@ -45,7 +47,9 @@ class PitchStatisticService {
}

getSuccessCount() {
return _(this.stats).filter(el => el.success).value().length;
return _(this.stats)
.filter(el => el.success)
.value().length;
}

rateEvent(event) {
Expand All @@ -67,7 +71,10 @@ class PitchStatisticService {
}

getLastTimes(n = 10) {
return this.stats.filter(el => el.success).map(el => el.time).slice(-n);
return this.stats
.filter(el => el.success)
.map(el => el.time)
.slice(-n);
}

computeAverage(array) {
Expand All @@ -83,11 +90,18 @@ class PitchStatisticService {
}

getTotalAmountOfChords() {
return _(this.stats).filter(el => el.success).map(el => el.keys).size();
return _(this.stats)
.filter(el => el.success)
.map(el => el.keys)
.size();
}

getTotalAmountOfKeys() {
return _(this.stats).filter(el => el.success).map(el => el.keys).flatten().size();
return _(this.stats)
.filter(el => el.success)
.map(el => el.keys)
.flatten()
.size();
}

getSuccessRate() {
Expand Down
14 changes: 11 additions & 3 deletions app/scripts/services/rhythm_statistic_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ class RhythmStatisticService {
}

getSuccessCount() {
return _(this.stats).filter(el => el.success).value().length;
return _(this.stats)
.filter(el => el.success)
.value().length;
}

getLastScores(n) {
return this.stats.slice(-n).map(this.rateEvent);
}

getLastTimes(n = 10) {
return this.stats.filter(el => el.success).map(el => el.time).slice(-n);
return this.stats
.filter(el => el.success)
.map(el => el.time)
.slice(-n);
}

computeAverage(array) {
Expand All @@ -88,7 +93,10 @@ class RhythmStatisticService {
}

getTotalAmountOfBeats() {
return _(this.stats).map(el => el.durations).flatten().size();
return _(this.stats)
.map(el => el.durations)
.flatten()
.size();
}

getTotalRhythmTime() {
Expand Down
10 changes: 4 additions & 6 deletions app/scripts/views/animated_number.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Motion, spring } from "react-motion";

export default class AnimatedNumber extends Component {
static propTypes = {
formatter: React.PropTypes.func,
number: React.PropTypes.number
formatter: PropTypes.func,
number: PropTypes.number
};
render() {
const formatter = this.props.formatter;
const number = this.props.number;
return (
<Motion defaultStyle={{ x: 1 }} style={{ x: spring(number) }}>
{value =>
<span>
{formatter ? formatter(value.x) : Math.round(value.x)}
</span>}
{value => <span>{formatter ? formatter(value.x) : Math.round(value.x)}</span>}
</Motion>
);
}
Expand Down
33 changes: 15 additions & 18 deletions app/scripts/views/beat_visualization.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import _ from "lodash";

import RhythmChecker from "../services/rhythm_checker.js";

export default class BeatVisualization extends Component {
static propTypes = {
settings: React.PropTypes.object.isRequired,
barDuration: React.PropTypes.number.isRequired,
currentRhythm: React.PropTypes.object.isRequired,
beatHistory: React.PropTypes.object.isRequired,
result: React.PropTypes.object.isRequired
settings: PropTypes.object.isRequired,
barDuration: PropTypes.number.isRequired,
currentRhythm: PropTypes.object.isRequired,
beatHistory: PropTypes.array.isRequired,
result: PropTypes.object
};

convertTicksToBeatNames(tickTime, tickLength) {
Expand All @@ -26,11 +27,11 @@ export default class BeatVisualization extends Component {
const ticks = necessaryBeatNames.slice(tickIndex, tickIndex + tickStepCount);
return (
<div className="row center-xs">
{ticks.map((beatName, index) =>
{ticks.map((beatName, index) => (
<div className="col-xs" key={index}>
{beatName}
</div>
)}
))}
</div>
);
}
Expand All @@ -52,11 +53,11 @@ export default class BeatVisualization extends Component {
currentX = x + width;

return [
marginLeft > 0
? <div className="beat restBeat" style={{ width: `${marginLeft}%` }} key={"spacer-${index}"}>
{beatNamesRest}
</div>
: null,
marginLeft > 0 ? (
<div className="beat restBeat" style={{ width: `${marginLeft}%` }} key={"spacer-${index}"}>
{beatNamesRest}
</div>
) : null,
<div className={`beat ${color}-beat`} style={{ width: `${width}%` }} key={index}>
{beatNames}
</div>
Expand Down Expand Up @@ -98,12 +99,8 @@ export default class BeatVisualization extends Component {
// uniqueId avoids that different beat bars are animated into each other
return (
<div key={_.uniqueId()} className={className}>
<div className="expectedBeatBar">
{expectedBeats}
</div>
<div className="actualBeatBar">
{actualBeats}
</div>
<div className="expectedBeatBar">{expectedBeats}</div>
<div className="actualBeatBar">{actualBeats}</div>
</div>
);
}
Expand Down
17 changes: 8 additions & 9 deletions app/scripts/views/claviature_view.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import KeyConverter from "../services/key_converter.js";
import classNames from "classnames";

export default class ClaviatureView extends Component {
static propTypes = {
desiredKeys: React.PropTypes.array,
keySignature: React.PropTypes.string,
successCallback: React.PropTypes.func,
failureCallback: React.PropTypes.func,
disabled: React.PropTypes.bool
desiredKeys: PropTypes.array,
keySignature: PropTypes.string,
successCallback: PropTypes.func,
failureCallback: PropTypes.func,
disabled: PropTypes.bool
};

constructor(props, context) {
Expand All @@ -20,7 +21,7 @@ export default class ClaviatureView extends Component {
}

static contextTypes = {
isInActiveView: React.PropTypes.bool
isInActiveView: PropTypes.bool
};

isNoteCorrect(noteName) {
Expand Down Expand Up @@ -110,9 +111,7 @@ export default class ClaviatureView extends Component {
].map(args => this.renderKey.apply(this, args));
return (
<div className={classNames({ "scale noSelect": true, noPointerEvents: this.props.disabled })}>
<ol>
{keys}
</ol>
<ol>{keys}</ol>
</div>
);
}
Expand Down
13 changes: 7 additions & 6 deletions app/scripts/views/collapsable_container.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import _ from "lodash";

export default class BeatVisualization extends Component {
export default class CollapsableContainer extends Component {
static propTypes = {
children: React.PropTypes.node,
collapsed: React.PropTypes.bool.isRequired,
maxHeight: React.PropTypes.number,
freeze: React.PropTypes.bool,
className: React.PropTypes.string
children: PropTypes.node,
collapsed: PropTypes.bool.isRequired,
maxHeight: PropTypes.number,
freeze: PropTypes.bool,
className: PropTypes.string
};

componentWillReceiveProps(nextProps) {
Expand Down
31 changes: 13 additions & 18 deletions app/scripts/views/game_button.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Button } from "react-bootstrap";

export default class GameButton extends Component {
static propTypes = {
label: React.PropTypes.string.isRequired,
onClick: React.PropTypes.func.isRequired,
primary: React.PropTypes.bool,
shortcutLetter: React.PropTypes.string
label: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
primary: PropTypes.bool,
shortcutLetter: PropTypes.string
};

static contextTypes = {
isInActiveView: React.PropTypes.bool
isInActiveView: PropTypes.bool
};

componentDidMount() {
Expand Down Expand Up @@ -38,22 +39,16 @@ export default class GameButton extends Component {
}

render() {
const subtext = this.props.shortcutLetter
? <div>
<span style={{ fontSize: 12 }}>
Or press '{this.props.shortcutLetter}'
</span>
</div>
: null;
const subtext = this.props.shortcutLetter ? (
<div>
<span style={{ fontSize: 12 }}>Or press &lsquo;{this.props.shortcutLetter}&rsquo;</span>
</div>
) : null;

return (
<Button onClick={this.props.onClick} bsStyle={this.props.primary ? "success" : "default"} className="gameButton">
<span className="gameButton-label">
{this.props.label}
</span>
<span className="subtext">
{subtext}
</span>
<span className="gameButton-label">{this.props.label}</span>
<span className="subtext">{subtext}</span>
</Button>
);
}
Expand Down
7 changes: 3 additions & 4 deletions app/scripts/views/level_view.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import _ from "lodash";
import React, { Component } from "react";
import PropTypes from "prop-types";
import LevelService from "../services/level_service.js";
import PieChart from "../views/pie_chart.js";

export default class LevelView extends Component {
static propTypes = {
statisticService: React.PropTypes.object.isRequired
statisticService: PropTypes.object.isRequired
};

render() {
Expand Down Expand Up @@ -64,9 +65,7 @@ export default class LevelView extends Component {
return (
<div>
{content}
<div>
Current level: {levelIndex + 2}
</div>
<div>Current level: {levelIndex + 2}</div>
</div>
);
}
Expand Down
10 changes: 4 additions & 6 deletions app/scripts/views/metronome_view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import _ from "lodash";

Expand All @@ -7,9 +8,8 @@ import CollapsableContainer from "./collapsable_container.js";

export default class MetronomeView extends Component {
static propTypes = {
onMetronomeEnded: React.PropTypes.func,
settings: React.PropTypes.object.isRequired,
statisticService: React.PropTypes.object.isRequired
onMetronomeEnded: PropTypes.func,
settings: PropTypes.object.isRequired
};

constructor(props, context) {
Expand Down Expand Up @@ -65,9 +65,7 @@ export default class MetronomeView extends Component {
opacityOut: (this.state.currentMetronomeBeat + 1) % 4 === 0
})}
>
<h2>
{this.state.currentMetronomeBeat + 1}
</h2>
<h2>{this.state.currentMetronomeBeat + 1}</h2>
</CollapsableContainer>
);
}
Expand Down
Loading

0 comments on commit 7368e67

Please sign in to comment.