1
1
import { computed , Ref , ref } from 'vue'
2
2
import { isString , SwipeDirection , timestamp , useSwipe } from '@vueuse/core'
3
- import { query } from '../state'
4
3
import { rawRoutes , router } from '../routes'
5
4
import { configs } from '../env'
5
+ import { useRouteQuery } from './route'
6
6
7
7
export { rawRoutes }
8
8
9
9
export const route = computed ( ( ) => router . currentRoute . value )
10
10
11
11
export const isPresenter = computed ( ( ) => route . value . path . startsWith ( '/presenter' ) )
12
12
13
+ export const queryClicks = useRouteQuery ( 'clicks' , '0' )
13
14
export const total = computed ( ( ) => rawRoutes . length - 1 )
14
15
export const path = computed ( ( ) => route . value . path )
15
16
@@ -25,13 +26,13 @@ export const nextRoute = computed(() => rawRoutes.find(i => i.path === `${Math.m
25
26
export const clicksElements = computed < HTMLElement [ ] > ( ( ) => currentRoute . value ?. meta ?. __clicksElements || [ ] )
26
27
export const clicks = computed < number > ( {
27
28
get ( ) {
28
- let clicks = + query . clicks || 0
29
+ let clicks = + ( queryClicks . value || 0 )
29
30
if ( isNaN ( clicks ) )
30
31
clicks = 0
31
32
return clicks
32
33
} ,
33
34
set ( v ) {
34
- query . clicks = v . toString ( )
35
+ queryClicks . value = v . toString ( )
35
36
} ,
36
37
} )
37
38
@@ -47,7 +48,6 @@ export function next() {
47
48
export async function prev ( ) {
48
49
if ( clicks . value <= 0 )
49
50
await prevSlide ( )
50
-
51
51
else
52
52
clicks . value -= 1
53
53
}
@@ -63,14 +63,11 @@ export function nextSlide() {
63
63
64
64
export async function prevSlide ( lastClicks = true ) {
65
65
const next = Math . max ( 1 , currentPage . value - 1 )
66
- await go ( next )
67
- if ( lastClicks )
68
- clicks . value = clicksTotal . value
66
+ await go ( next , ( lastClicks && clicksTotal . value ) ? clicksTotal . value : undefined )
69
67
}
70
68
71
- export function go ( page : number ) {
72
- clicks . value = 0
73
- return router . push ( getPath ( page ) )
69
+ export function go ( page : number , clicks ?: number ) {
70
+ return router . push ( { path : getPath ( page ) , query : { ...route . value . query , clicks } } )
74
71
}
75
72
76
73
export function useSwipeControls ( root : Ref < HTMLElement | undefined > ) {
@@ -109,3 +106,5 @@ export async function downloadPDF() {
109
106
`${ configs . title } .pdf` ,
110
107
)
111
108
}
109
+
110
+ export const isPrintMode = computed ( ( ) => route . value . query . print !== undefined )
0 commit comments