Skip to content

Commit

Permalink
fix: how nav direction is calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 24, 2024
1 parent cf80a07 commit 83e9c78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/client/internals/SlideContainer.vue
Expand Up @@ -3,7 +3,7 @@ import { provideLocal, useElementSize, useStyleTag } from '@vueuse/core'
import { computed, ref, watchEffect } from 'vue'
import { configs, slideAspect, slideHeight, slideWidth } from '../env'
import { injectionSlideScale } from '../constants'
import { isPrintMode, navDirection } from '../logic/nav'
import { clicksDirection, isPrintMode, navDirection } from '../logic/nav'
const props = defineProps({
width: {
Expand Down Expand Up @@ -55,8 +55,8 @@ const style = computed(() => ({
const className = computed(() => ({
'select-none': !configs.selectable,
'slidev-nav-go-forward': navDirection.value > 0,
'slidev-nav-go-backward': navDirection.value < 0,
'slidev-nav-go-forward': clicksDirection.value > 0,
'slidev-nav-go-backward': clicksDirection.value < 0,
}))
if (props.isMain) {
Expand Down
5 changes: 5 additions & 0 deletions packages/client/logic/nav.ts
Expand Up @@ -22,6 +22,7 @@ nextTick(() => {
})

export const navDirection = ref(0)
export const clicksDirection = ref(0)

export const route = computed(() => router.currentRoute.value)

Expand Down Expand Up @@ -84,13 +85,15 @@ watch(currentRoute, (next, prev) => {
})

export async function next() {
clicksDirection.value = 1
if (clicksTotal.value <= queryClicks.value)
await nextSlide()
else
queryClicks.value += 1
}

export async function prev() {
clicksDirection.value = -1
if (queryClicks.value <= 0)
await prevSlide()
else
Expand All @@ -102,11 +105,13 @@ export function getPath(no: number | string) {
}

export async function nextSlide() {
clicksDirection.value = 1
if (currentPage.value < rawRoutes.length)
await go(currentPage.value + 1)
}

export async function prevSlide(lastClicks = true) {
clicksDirection.value = -1
const next = Math.max(1, currentPage.value - 1)
await go(next)
if (lastClicks && clicksTotal.value)
Expand Down

0 comments on commit 83e9c78

Please sign in to comment.