(action) add pause button

This commit is contained in:
2020-07-11 00:52:38 +02:00
parent bb2df9ea79
commit b81983acdf
2 changed files with 15 additions and 3 deletions

View File

@@ -33,7 +33,7 @@ export const useTimer = () => {
const start = () => { const start = () => {
timeState.value = 'started' timeState.value = 'started'
notify('La session commence !') notify(seconds.value ? 'La session reprend !' : 'La session commence !')
stopwatchId = setInterval(() => { stopwatchId = setInterval(() => {
seconds.value++ seconds.value++
@@ -54,7 +54,7 @@ export const useTimer = () => {
}, 1000) }, 1000)
} }
const clear = () => { const pause = () => {
timeState.value = 'stopped' timeState.value = 'stopped'
if (stopwatchId) { if (stopwatchId) {
clearInterval(stopwatchId) clearInterval(stopwatchId)
@@ -64,6 +64,10 @@ export const useTimer = () => {
clearInterval(stopWatchSessionId) clearInterval(stopWatchSessionId)
stopWatchSessionId = null stopWatchSessionId = null
} }
}
const clear = () => {
pause()
seconds.value = 0 seconds.value = 0
sessionSeconds.value = intervalSeconds.value sessionSeconds.value = intervalSeconds.value
isProgrammer1Turn.value = true isProgrammer1Turn.value = true
@@ -72,6 +76,7 @@ export const useTimer = () => {
return { return {
interval, interval,
start, start,
pause,
clear, clear,
timeState, timeState,
time, time,

View File

@@ -20,6 +20,7 @@
<div class="global-time">{{ time }}</div> <div class="global-time">{{ time }}</div>
<div class="actions"> <div class="actions">
<button v-show="timeState === 'stopped'" @click="start">commencer</button> <button v-show="timeState === 'stopped'" @click="start">commencer</button>
<button v-show="timeState === 'started'" @click="pause">pause</button>
<button v-show="timeState === 'started'" @click="clear">arrêter</button> <button v-show="timeState === 'started'" @click="clear">arrêter</button>
</div> </div>
<div class="music"> <div class="music">
@@ -38,7 +39,7 @@
v-if="hasMusic" v-if="hasMusic"
:play="timeState === 'started'" :play="timeState === 'started'"
@play="start" @play="start"
@pause="clear" @pause="pause"
/> />
</div> </div>
</div> </div>
@@ -64,6 +65,7 @@ export default defineComponent({
const { const {
interval, interval,
start, start,
pause,
clear, clear,
timeState, timeState,
time, time,
@@ -77,6 +79,7 @@ export default defineComponent({
hasMusic, hasMusic,
interval, interval,
start, start,
pause,
clear, clear,
timeState, timeState,
time, time,
@@ -101,6 +104,10 @@ export default defineComponent({
flex-wrap: wrap; flex-wrap: wrap;
} }
button {
margin: 0 1rem;
}
.global-time { .global-time {
font-size: calc(3em + 10vw); font-size: calc(3em + 10vw);
} }