when timer runs, entire #timer section turns green, not just Timer component

practiced-songs
Matthew Huntington 1 year ago
parent c61458e64d
commit ddea612f3a

@ -9,6 +9,8 @@
const currentWorkingCategory = ref(null) const currentWorkingCategory = ref(null)
const currentWorkingInstrument = ref(null) const currentWorkingInstrument = ref(null)
const timerRunning = ref(false)
const micThresholdExceeded = ref(false)
const summaryRef = ref(null) const summaryRef = ref(null)
const statusRef = ref(null) const statusRef = ref(null)
const showCategoryRef = ref(null) const showCategoryRef = ref(null)
@ -34,13 +36,15 @@
<template> <template>
<main> <main>
<section id="timer"> <section id="timer" :class="{timerRunning:timerRunning, micThresholdExceeded:micThresholdExceeded}">
<Status ref="statusRef"/> <Status ref="statusRef"/>
<Timer <Timer
v-if="currentWorkingInstrument" v-if="currentWorkingInstrument"
@loggedTime="refreshPage" @loggedTime="refreshPage"
:instruments="instruments" :instruments="instruments"
:categories="categories" :categories="categories"
v-model:timerRunning="timerRunning"
v-model:micThresholdExceeded="micThresholdExceeded"
v-model:currentWorkingInstrument="currentWorkingInstrument" v-model:currentWorkingInstrument="currentWorkingInstrument"
v-model:currentWorkingCategory="currentWorkingCategory"/> v-model:currentWorkingCategory="currentWorkingCategory"/>
</section> </section>
@ -66,3 +70,13 @@
</section> </section>
</main> </main>
</template> </template>
<style scoped>
.timerRunning {
background:lightgreen;
}
.timerRunning.micThresholdExceeded {
background:green;
}
</style>

@ -1,5 +1,7 @@
<script setup> <script setup>
import { onMounted, getCurrentInstance } from 'vue' import { onMounted, getCurrentInstance } from 'vue'
const micThresholdExceeded = defineModel('micThresholdExceeded')
const timerRunning = defineModel('timerRunning')
const currentWorkingCategory = defineModel('currentWorkingCategory') const currentWorkingCategory = defineModel('currentWorkingCategory')
const currentWorkingInstrument = defineModel('currentWorkingInstrument') const currentWorkingInstrument = defineModel('currentWorkingInstrument')
const props = defineProps(['categories', 'instruments']) const props = defineProps(['categories', 'instruments'])
@ -25,7 +27,6 @@
export default { export default {
data() { data() {
return { return {
running: false,
startTime:0, startTime:0,
savedPreviousSeconds:0, savedPreviousSeconds:0,
totalSeconds:0, totalSeconds:0,
@ -38,7 +39,6 @@
secondsToSubtract:0, secondsToSubtract:0,
micThreshold:-1, micThreshold:-1,
micLevel:0, micLevel:0,
micThresholdExceeded:false,
practice_category_id:0 practice_category_id:0
} }
}, },
@ -78,9 +78,9 @@
}, },
start(event){ start(event){
if(this.running === false){ if(this.timerRunning === false){
this.startTime = Date.now(); this.startTime = Date.now();
this.running = true; this.$emit('update:timerRunning', true)
this.intervalID = setInterval(()=>{ this.intervalID = setInterval(()=>{
if(this.micThreshold > -1){ if(this.micThreshold > -1){
@ -97,9 +97,9 @@
} }
if(this.micLevel >= this.micThreshold){ if(this.micLevel >= this.micThreshold){
this.micThresholdExceeded = true; this.$emit('update:micThresholdExceeded', true)
} else { } else {
this.micThresholdExceeded = false; this.$emit('update:micThresholdExceeded', false)
} }
this.totalSeconds = getAccumulatedSeconds(Date.now(), this.startTime) - this.secondsToSubtract + this.savedPreviousSeconds; this.totalSeconds = getAccumulatedSeconds(Date.now(), this.startTime) - this.secondsToSubtract + this.savedPreviousSeconds;
@ -119,8 +119,8 @@
this.setManualTime(this.totalSeconds) this.setManualTime(this.totalSeconds)
}, },
stop(event){ stop(event){
if(this.running === true){ if(this.timerRunning === true){
this.running = false; this.$emit('update:timerRunning', false)
this.savedPreviousSeconds += getAccumulatedSeconds(Date.now(), this.startTime); this.savedPreviousSeconds += getAccumulatedSeconds(Date.now(), this.startTime);
clearInterval(this.intervalID); clearInterval(this.intervalID);
} }
@ -191,15 +191,15 @@
<template> <template>
<h2>Timer</h2> <h2>Timer</h2>
<div :class="{running:running, micThresholdExceeded:micThresholdExceeded}"> <div>
<em> <em>
{{formatSeconds(totalSeconds)}} {{formatSeconds(totalSeconds)}}
</em> </em>
Mic Threshold (current level: {{Math.round(micLevel)}}): Mic Threshold (current level: {{Math.round(micLevel)}}):
<input type="number" @change="activateMic" v-model="micThreshold"/> <input type="number" @change="activateMic" v-model="micThreshold"/>
<button :disabled="running" @click="start">Start</button> <button :disabled="timerRunning" @click="start">Start</button>
<button :disabled="!running" @click="stop">Stop</button> <button :disabled="!timerRunning" @click="stop">Stop</button>
<button :disabled="running || totalSeconds === 0" @click="reset">Reset</button> <button :disabled="timerRunning || totalSeconds === 0" @click="reset">Reset</button>
</div> </div>
<form @submit="submit"> <form @submit="submit">
<label>Description</label> <label>Description</label>
@ -237,14 +237,6 @@ input[type="number"] {
width: 5em; width: 5em;
} }
.running {
background:lightgreen;
}
.running.micThresholdExceeded {
background:green;
}
button, em { button, em {
margin: 1em 0; margin: 1em 0;
display:block; display:block;

Loading…
Cancel
Save