Skip to content

Commit

Permalink
feat: pause/resume timer (#1928)
Browse files Browse the repository at this point in the history
Co-authored-by: _Kerman <kermanx@qq.com>
  • Loading branch information
ken7253 and KermanX authored Nov 18, 2024
1 parent a4456b7 commit 3ba948c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
20 changes: 20 additions & 0 deletions packages/client/composables/useTimer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useInterval } from '@vueuse/core'
import { computed } from 'vue'

export function useTimer() {
const { counter, isActive, reset, pause, resume } = useInterval(1000, { controls: true })

const timer = computed(() => {
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}`
})

return {
timer,
isTimerAvctive: isActive,
resetTimer: reset,
toggleTimer: () => (isActive.value ? pause() : resume()),
}
}
23 changes: 0 additions & 23 deletions packages/client/logic/utils.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
import { parseRangeString } from '@slidev/parser/core'
import { useTimestamp } from '@vueuse/core'
import { computed, ref } from 'vue'

export function useTimer() {
const tsStart = ref(Date.now())
const now = useTimestamp({
interval: 1000,
})
const timer = computed(() => {
const passed = (now.value - tsStart.value) / 1000
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
}

return {
timer,
resetTimer,
}
}

export function makeId(length = 5) {
const result = []
Expand Down
37 changes: 18 additions & 19 deletions packages/client/pages/presenter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createFixedClicks } from '../composables/useClicks'
import { useDrawings } from '../composables/useDrawings'
import { useNav } from '../composables/useNav'
import { useSwipeControls } from '../composables/useSwipeControls'
import { useTimer } from '../composables/useTimer'
import { useWakeLock } from '../composables/useWakeLock'
import { slidesTitle } from '../env'
import ClicksSlider from '../internals/ClicksSlider.vue'
Expand All @@ -22,7 +23,6 @@ import SlidesShow from '../internals/SlidesShow.vue'
import SlideWrapper from '../internals/SlideWrapper.vue'
import { onContextMenu } from '../logic/contextMenu'
import { registerShortcuts } from '../logic/shortcuts'
import { useTimer } from '../logic/utils'
import { decreasePresenterFontSize, increasePresenterFontSize, presenterLayout, presenterNotesFontSize, showEditor, showPresenterCursor } from '../state'
import { sharedState } from '../state/shared'
Expand All @@ -49,7 +49,7 @@ useHead({ title: `Presenter - ${slidesTitle}` })
const notesEditing = ref(false)
const { timer, resetTimer } = useTimer()
const { timer, isTimerAvctive, resetTimer, toggleTimer } = useTimer()
const clicksCtxMap = computed(() => slides.value.map(route => createFixedClicks(route)))
const nextFrame = computed(() => {
Expand Down Expand Up @@ -184,16 +184,22 @@ onMounted(() => {
<div class="grid-section bottom flex">
<NavControls :persist="true" />
<div flex-auto />
<div
class="timer-btn my-auto relative w-22px h-22px cursor-pointer text-lg"
opacity="50 hover:100"
@click="resetTimer"
>
<carbon:time class="absolute" />
<carbon:renew class="absolute opacity-0" />
</div>
<div class="text-2xl pl-2 pr-6 my-auto tabular-nums">
{{ timer }}
<div class="group flex items-center justify-center pl-4 select-none">
<div class="w-22px cursor-pointer">
<carbon:time class="group-hover:hidden text-xl" />
<div class="group-not-hover:hidden flex flex-col items-center">
<div class="relative op-80 hover:op-100" @click="toggleTimer">
<carbon:pause v-if="isTimerAvctive" class="text-lg" />
<carbon:play v-else />
</div>
<div class="op-80 hover:op-100" @click="resetTimer">
<carbon:renew />
</div>
</div>
</div>
<div class="text-2xl px-3 my-auto tabular-nums">
{{ timer }}
</div>
</div>
</div>
<DrawingControls v-if="__SLIDEV_FEATURE_DRAWINGS__" />
Expand All @@ -215,13 +221,6 @@ onMounted(() => {
--slidev-controls-foreground: current;
}
.timer-btn:hover > :first-child {
opacity: 0;
}
.timer-btn:hover > :last-child {
opacity: 1;
}
.grid-container {
--uno: bg-gray/20;
height: 100%;
Expand Down

0 comments on commit 3ba948c

Please sign in to comment.