Skip to content

Commit

Permalink
Upgrade prettier and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham42 committed Oct 11, 2017
1 parent a177ee7 commit 0226757
Show file tree
Hide file tree
Showing 21 changed files with 183 additions and 154 deletions.
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
5 changes: 1 addition & 4 deletions app/scripts/views/animated_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ export default class AnimatedNumber extends Component {
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
22 changes: 9 additions & 13 deletions app/scripts/views/beat_visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,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 @@ -53,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 @@ -99,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
4 changes: 1 addition & 3 deletions app/scripts/views/claviature_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,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
20 changes: 7 additions & 13 deletions app/scripts/views/game_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,16 @@ export default class GameButton extends Component {
}

render() {
const subtext = this.props.shortcutLetter
? <div>
<span style={{ fontSize: 12 }}>
Or press &lsquo;{this.props.shortcutLetter}&rsquo;
</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
4 changes: 1 addition & 3 deletions app/scripts/views/level_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,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
4 changes: 1 addition & 3 deletions app/scripts/views/metronome_view.js
Original file line number Diff line number Diff line change
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
22 changes: 10 additions & 12 deletions app/scripts/views/pitch_reading_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ export default class PitchReadingView extends Component {
const isMidiAvailable = this.props.settings.midi.inputs.get().length > 0;
const noErrors = this.state.errorMessage !== null;
const miniClaviature =
isMidiAvailable && noErrors
? null
: <ClaviatureView
desiredKeys={this.getAllCurrentKeys()}
keySignature={this.state.currentKeySignature}
successCallback={this.onSuccess.bind(this)}
failureCallback={this.onFailure.bind(this)}
disabled={!this.state.running}
/>;
isMidiAvailable && noErrors ? null : (
<ClaviatureView
desiredKeys={this.getAllCurrentKeys()}
keySignature={this.state.currentKeySignature}
successCallback={this.onSuccess.bind(this)}
failureCallback={this.onFailure.bind(this)}
disabled={!this.state.running}
/>
);

const startStopButton = (
<GameButton
Expand Down Expand Up @@ -226,9 +226,7 @@ export default class PitchReadingView extends Component {
hide: this.state.errorMessage === null
})}
>
<h3>
{this.state.errorMessage}
</h3>
<h3>{this.state.errorMessage}</h3>
</div>
</div>
</CollapsableContainer>
Expand Down
40 changes: 20 additions & 20 deletions app/scripts/views/pitch_settings_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ export default class PitchSettingsView extends Component {
const midiSettings = this.props.settings.midi;
const midiInputs = midiSettings.inputs.get();
const isMidiAvailable = midiInputs.length > 0;
const deviceSelector = !isMidiAvailable
? null
: <SettingLine label="Midi device">
<select
name="select"
onChange={this.onMidiSelectChange.bind(this)}
defaultValue={midiSettings.currentInput}
ref={c => {
this.midiSelect = c;
}}
>
{midiInputs.map((el, index) => {
return (
<option value={index} key={index}>
Device {index + 1}
</option>
);
})}
</select>
</SettingLine>;
const deviceSelector = !isMidiAvailable ? null : (
<SettingLine label="Midi device">
<select
name="select"
onChange={this.onMidiSelectChange.bind(this)}
defaultValue={midiSettings.currentInput}
ref={c => {
this.midiSelect = c;
}}
>
{midiInputs.map((el, index) => {
return (
<option value={index} key={index}>
Device {index + 1}
</option>
);
})}
</select>
</SettingLine>
);

const useAutomaticDifficulty = this.props.settings.useAutomaticDifficulty;

Expand Down
28 changes: 14 additions & 14 deletions app/scripts/views/rhythm_reading_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,19 @@ export default class RhythmReadingView extends Component {
);

const buttons =
this.state.phase !== Phases.feedback
? <GameButton label="Start training" shortcutLetter="s" primary onClick={this.nextBar.bind(this)} />
: this.state.result.success
? <div>
<GameButton label="Repeat this bar" shortcutLetter="r" onClick={this.repeatBar.bind(this)} />
<GameButton label="Start next bar" shortcutLetter="s" onClick={this.nextBar.bind(this)} primary />
</div>
: <div>
<GameButton label="Repeat this bar" shortcutLetter="r" onClick={this.repeatBar.bind(this)} primary />
<GameButton label="Skip this bar" shortcutLetter="s" onClick={this.nextBar.bind(this)} />
</div>;
this.state.phase !== Phases.feedback ? (
<GameButton label="Start training" shortcutLetter="s" primary onClick={this.nextBar.bind(this)} />
) : this.state.result.success ? (
<div>
<GameButton label="Repeat this bar" shortcutLetter="r" onClick={this.repeatBar.bind(this)} />
<GameButton label="Start next bar" shortcutLetter="s" onClick={this.nextBar.bind(this)} primary />
</div>
) : (
<div>
<GameButton label="Repeat this bar" shortcutLetter="r" onClick={this.repeatBar.bind(this)} primary />
<GameButton label="Skip this bar" shortcutLetter="s" onClick={this.nextBar.bind(this)} />
</div>
);

return (
<div className={classNames({ trainer: true, trainerHidden2: !this.props.isActive })}>
Expand All @@ -296,9 +298,7 @@ export default class RhythmReadingView extends Component {

<CollapsableContainer collapsed={this.state.phase === Phases.running}>
<div className="row center-xs" style={{ marginTop: 20 }}>
<div className="col-xs-12">
{buttons}
</div>
<div className="col-xs-12">{buttons}</div>
</div>
</CollapsableContainer>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/views/rhythm_statistic_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ export default class RhythmStatisticView extends Component {
unit: "y"
},
{
amount: Math.floor(seconds % 31536000 / 86400),
amount: Math.floor((seconds % 31536000) / 86400),
unit: "d"
},
{
amount: Math.floor(seconds % 31536000 % 86400 / 3600),
amount: Math.floor(((seconds % 31536000) % 86400) / 3600),
unit: "h"
},
{
amount: Math.floor(seconds % 31536000 % 86400 % 3600 / 60),
amount: Math.floor((((seconds % 31536000) % 86400) % 3600) / 60),
unit: "m"
},
{
amount: seconds % 31536000 % 86400 % 3600 % 60,
amount: (((seconds % 31536000) % 86400) % 3600) % 60,
unit: "s"
}
]
Expand Down
4 changes: 1 addition & 3 deletions app/scripts/views/setting_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export default class SettingLine extends Component {
<div className="col-lg-6 col-md-6 col-sm-6 col-xs-12" style={{ textAlign: "left" }}>
{this.props.label}
</div>
<div className="settingUI col-lg-6 col-md-6 col-sm-6 col-xs-12">
{this.props.children}
</div>
<div className="settingUI col-lg-6 col-md-6 col-sm-6 col-xs-12">{this.props.children}</div>
</div>
);
}
Expand Down
10 changes: 8 additions & 2 deletions app/scripts/views/stave_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ class StaveRenderer extends PureComponent {
this.setCanvasExtent(canvas, width, height, ratio);

const rightHandStave = new Vex.Flow.Stave(10, 0, staveWidth);
rightHandStave.addClef("treble").setKeySignature(this.props.keySignature).setContext(ctx);
rightHandStave
.addClef("treble")
.setKeySignature(this.props.keySignature)
.setContext(ctx);

const leftHandStave = new Vex.Flow.Stave(10, 80, staveWidth);
leftHandStave.addClef("bass").setKeySignature(this.props.keySignature).setContext(ctx);
leftHandStave
.addClef("bass")
.setKeySignature(this.props.keySignature)
.setContext(ctx);

this.colorizeKeys();

Expand Down
Loading

0 comments on commit 0226757

Please sign in to comment.