Skip to content

Commit

Permalink
Implement stop and resume logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
ken7253 committed Nov 1, 2024
1 parent fe65190 commit b415a0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
19 changes: 7 additions & 12 deletions packages/client/logic/utils.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import { parseRangeString } from '@slidev/parser/core'
import { useTimestamp } from '@vueuse/core'
import { useInterval } from '@vueuse/core'
import { computed, ref } from 'vue'

export function useTimer() {
const tsStart = ref(Date.now())
const stop = ref(false)
const now = useTimestamp({
interval: 1000,
})
const { counter, reset, pause, resume } = useInterval(1000, { controls: true })
const timer = computed(() => {
const passed = (now.value - tsStart.value) / 1000
const passed = counter.value
const sec = Math.floor(passed % 60).toString().padStart(2, '0')
const min = Math.floor(passed / 60).toString().padStart(2, '0')
return `${min}:${sec}`
})
function resetTimer() {
tsStart.value = now.value
}

function stopTimer() {
function toggleTimer() {
stop.value = !stop.value
stop.value ? pause() : resume()
}

return {
timer,
stop,
resetTimer,
stopTimer,
resetTimer: reset,
toggleTimer,
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/client/pages/presenter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ useHead({ title: `Presenter - ${slidesTitle}` })
const notesEditing = ref(false)
const { timer, stop, resetTimer, stopTimer } = useTimer()
const { timer, stop, resetTimer, toggleTimer } = useTimer()
const clicksCtxMap = computed(() => slides.value.map(route => createFixedClicks(route)))
const nextFrame = computed(() => {
Expand Down Expand Up @@ -198,7 +198,7 @@ onMounted(() => {
<label
class="stop-button my-auto mr-4 relative w-19px h-19px cursor-pointer"
>
<input class="hidden" type="checkbox" @change="stopTimer">
<input class="hidden" type="checkbox" @change="toggleTimer">
<carbon:pause v-if="!stop" class="absolute" />
<carbon:play v-if="stop" class="absolute opacity-0" />
</label>
Expand Down

0 comments on commit b415a0e

Please sign in to comment.