basics of timer functionality

mic_level
Matthew Huntington 3 years ago
parent d108b9ebb3
commit 9165723bbe

@ -1,9 +1,17 @@
<script lang="ts"> <script lang="ts">
import axios from 'axios'; import axios from 'axios';
const getAccumulatedSeconds = (newerTime, olderTime) => {
return Math.floor((newerTime-olderTime)/1000);
}
export default { export default {
data() { data() {
return { return {
categories:[] categories:[],
running: false,
startTime:0,
savedPreviousSeconds:0
} }
}, },
methods: { methods: {
@ -15,10 +23,12 @@
console.log(this.practice_category_id); console.log(this.practice_category_id);
}, },
start(event){ start(event){
console.log('starting'); this.startTime = Date.now();
this.running = true;
}, },
stop(event){ stop(event){
console.log('stopping'); this.running = false;
this.savedPreviousSeconds += getAccumulatedSeconds(Date.now(), this.startTime);
} }
}, },
mounted() { mounted() {
@ -32,14 +42,14 @@
<template> <template>
<details> <details>
<summary><h2>Timer</h2></summary> <summary><h2>Timer</h2></summary>
<button @click="start">Start Timer</button> <button :disabled="running" @click="start">Start Timer</button>
<button @click="stop">Stop Timer</button> <button :disabled="!running" @click="stop">Stop Timer</button>
<form @submit="submit"> <form @submit="submit">
<label>Description</label> <label>Description</label>
<input v-model="description" type="text"/> <input v-model="description" type="text"/>
<label>Seconds</label> <label>Seconds</label>
<input v-model="seconds" type="number"/> <input v-model="savedPreviousSeconds" type="number"/>
<label>Comments</label> <label>Comments</label>
<textarea v-model="comments"/> <textarea v-model="comments"/>

Loading…
Cancel
Save