Skip to content

Commit

Permalink
move to composables directory + update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Nov 3, 2024
1 parent b415a0e commit 95450a0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 58 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()),
}
}
25 changes: 0 additions & 25 deletions packages/client/logic/utils.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
import { parseRangeString } from '@slidev/parser/core'
import { useInterval } from '@vueuse/core'
import { computed, ref } from 'vue'

export function useTimer() {
const stop = ref(false)
const { counter, 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}`
})

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

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

export function makeId(length = 5) {
const result = []
Expand Down
51 changes: 18 additions & 33 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, stop, resetTimer, toggleTimer } = useTimer()
const { timer, isTimerAvctive, resetTimer, toggleTimer } = useTimer()
const clicksCtxMap = computed(() => slides.value.map(route => createFixedClicks(route)))
const nextFrame = computed(() => {
Expand Down Expand Up @@ -184,24 +184,23 @@ 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 px-3 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>
<label
class="stop-button my-auto mr-4 relative w-19px h-19px cursor-pointer"
>
<input class="hidden" type="checkbox" @change="toggleTimer">
<carbon:pause v-if="!stop" class="absolute" />
<carbon:play v-if="stop" class="absolute opacity-0" />
</label>
</div>
<DrawingControls v-if="__SLIDEV_FEATURE_DRAWINGS__" />
</div>
Expand All @@ -222,20 +221,6 @@ onMounted(() => {
--slidev-controls-foreground: current;
}
.timer-btn:hover > :first-child {
opacity: 0;
}
.timer-btn:hover > :last-child {
opacity: 1;
}
.stop-button:has(input[checked]) > :first-child {
opacity: 0;
}
.stop-button:not(:has(input[checked])) > :last-child {
opacity: 1;
}
.grid-container {
--uno: bg-gray/20;
height: 100%;
Expand Down

0 comments on commit 95450a0

Please sign in to comment.