Skip to content

Commit

Permalink
fixed null error, lint errors, CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruth Oldja committed Aug 10, 2020
1 parent f17c94d commit 241249a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
}
#nav {
padding: 30px;
padding: 10px;
color: rgb(15, 220, 121);
}
#nav a {
Expand Down
64 changes: 31 additions & 33 deletions src/components/TimerComponent.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component, Vue } from 'vue-property-decorator';
import WithRender from './timer-component.html';
import { SolveLog } from '@/models/SolveLog';
import { saveAs } from 'file-saver';
import _ from 'lodash';
import WithRender from './timer-component.html';
import Chart from 'chart.js';
import _ from 'lodash';
const cubeScrambler = require('cube-scrambler')();
const papa = require('papaparse');
const papa = require('papaparse');
require('../styles/timer-component.css');

@WithRender
Expand All @@ -25,15 +25,7 @@ export default class TimerComponent extends Vue {
{ key: 'dnf', label: 'DNF' },
];

private solves: SolveLog[] = [
{
// sessionId: 0,
// userId: 0,
id: 0,
time: 45.0,
dnf: true,
},
];
private solves: SolveLog[] = [];

private get sessionAverage(): number {
let sum: number = 0;
Expand All @@ -59,7 +51,7 @@ export default class TimerComponent extends Vue {
window.onkeydown = (e: KeyboardEvent): boolean => {
return !(e.keyCode === 32 && e.target === document.body);
};
window.onload = () => {
window.onload = () => {
this.$notify({
group: 'notifications',
text: 'Use SPACEBAR to start/stop timer. Use ESC to clear the timer.',
Expand All @@ -70,8 +62,8 @@ export default class TimerComponent extends Vue {
text: 'Click on the X in the DNF box to toggle DNF status.',
duration: -1,
});
}
let ctx = document.getElementById('solvesChart');
};
const ctx: HTMLElement = document.getElementById('solvesChart');
this.solvesChart = new Chart(ctx, {
type: 'line',
data: {
Expand All @@ -86,26 +78,27 @@ export default class TimerComponent extends Vue {
borderColor: [
'rgb(15, 220, 121)',
],
borderWidth: 1
}]
borderWidth: 1,
}],
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
beginAtZero: true,
},
}],
},
},
});
}

private timerTrigger(): void {
if (this.timerRunning) {
this.timerRunning = false;
let currentTime: number = Math.round(this.time * 1000) / 1000;
if (_.minBy(this.solves.filter((s: SolveLog): boolean => !s.dnf), 'time').time > currentTime) {
const currentTime: number = Math.round(this.time * 1000) / 1000;
const currentBest: SolveLog | null = _.minBy(this.solves.filter((s: SolveLog): boolean => !s.dnf), 'time');
if (currentBest ? currentBest.time > currentTime : true) {
this.bestTime = true;
}
this.solves.unshift(new SolveLog({ id: this.solveNumber, time: currentTime, dnf: false }));
Expand Down Expand Up @@ -140,15 +133,15 @@ export default class TimerComponent extends Vue {
}

private exportSolves(): void {
const csvData = papa.unparse(this.solves);
const blob = new Blob([csvData], {
type: 'data:text/csv;charset=utf-8'
const csvData: any = papa.unparse(this.solves);
const blob: Blob = new Blob([csvData], {
type: 'data:text/csv;charset=utf-8',
});
saveAs(blob, 'solves.csv');
}

private openSolves(): void {
let fileSelector = document.getElementById('file-input');
const fileSelector: HTMLElement = document.getElementById('file-input');
fileSelector.click();
}

Expand All @@ -161,18 +154,23 @@ export default class TimerComponent extends Vue {
complete: (results: any): void => {
this.solves = results.data.map((s: any): SolveLog => new SolveLog(s));
this.updateChart();
}
},
});
}
catch(error) {
} catch (error) {
console.error(error);
}
}

private updateChart(): void {
this.solvesChart.data.labels = this.solves.filter((s: SolveLog): boolean => !s.dnf).map((s: SolveLog): number => s.id).reverse();
this.solvesChart.data.labels = this.solves
.filter((s: SolveLog): boolean => !s.dnf)
.map((s: SolveLog): number => s.id)
.reverse();
this.solvesChart.data.datasets.forEach((dataset) => {
dataset.data = this.solves.filter((s: SolveLog): boolean => !s.dnf).map((s: SolveLog): number => s.time).reverse();
dataset.data = this.solves
.filter((s: SolveLog): boolean => !s.dnf)
.map((s: SolveLog): number => s.time)
.reverse();
});
this.solvesChart.update();
}
Expand Down
1 change: 1 addition & 0 deletions src/components/timer-component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<h1 :class="{ timer: true, bestTime: bestTime }">{{ time.toFixed(2) }}</h1>
<p class="average">session average: {{ sessionAverage === 0.00 ? '--' : sessionAverage.toFixed(2) }}</p>
</div>

<div class="chart">
<canvas id="solvesChart"></canvas>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import App from './App.vue';
import router from './router';
import store from './store';
import Notifications from 'vue-notification';
import Vue2TouchEvents from 'vue2-touch-events'
import Vue2TouchEvents from 'vue2-touch-events';
import BootstrapVue from 'bootstrap-vue';
import 'bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
Expand All @@ -13,7 +13,7 @@ import '@fortawesome/fontawesome-free/css/all.css';
import '@fortawesome/fontawesome-free/js/all.js';

Vue.use(Notifications);
Vue.use(Vue2TouchEvents)
Vue.use(Vue2TouchEvents);
Vue.use(BootstrapVue);
Vue.config.productionTip = false;

Expand Down
8 changes: 4 additions & 4 deletions src/models/SolveLog.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export class SolveLog {
public id: number;
// public sessionId: number;
// public userId: number | null;
public time: number;
public dnf: boolean | string;
// public sessionId: number;
// public userId: number | null;

constructor(solve: Partial<SolveLog> ) {
this.id = Number(solve.id);
// this.sessionId = Number(solve.sessionId);
// this.userId = Number(solve.userId);
this.time = Number(solve.time);
this.dnf = Boolean(solve.dnf);
// this.sessionId = Number(solve.sessionId);
// this.userId = Number(solve.userId);
}
}
14 changes: 10 additions & 4 deletions src/styles/timer-component.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@

.timer {
font-size: 3em;
padding: 3%;
padding: 1%;
padding-left: 5%;
padding-right: 5%;
}

@media (max-width:600px) {
.timer {
font-size: 2em;
}
}

.chart {
width: 75%;
margin: 0 auto;
}

.times {
font-size: 0.4em;
width: 75%;
font-size: 0.3em;
margin: 0 auto;
}

Expand Down

0 comments on commit 241249a

Please sign in to comment.