1
1
<script lang="ts" setup>
2
2
import { NTab , NTabs } from ' naive-ui' ;
3
- import { computed , toRefs , useSlots } from ' vue' ;
3
+ import { computed , ref , toRefs , useSlots } from ' vue' ;
4
4
import { useRoute , useRouter } from ' vue-router' ;
5
5
6
6
import NavbarSettingsDropdown from ' ~/components/common/navbar/NavbarSettingsDopdown.vue' ;
7
7
8
8
import { Route } from ' ~/models/router.model' ;
9
+ import { Logger } from ' ~/services/logger.service' ;
9
10
import { NavbarService } from ' ~/services/navbar.service' ;
10
11
import { useExtensionSettingsStoreRefs } from ' ~/stores/settings/extension.store' ;
12
+ import { Header } from ' ~/styles/layout.style' ;
11
13
import { useI18n } from ' ~/utils/i18n.utils' ;
14
+ import { handleSwipe , SwipeDirection } from ' ~/utils/touch.utils' ;
12
15
13
16
const props = defineProps ({
14
17
disabled: {
@@ -43,6 +46,21 @@ const activeRoute = computed(() => {
43
46
);
44
47
});
45
48
49
+ const nextRoute = computed (() => {
50
+ if (! activeRoute .value ) return ;
51
+ const index = activableRoutes .value .indexOf (activeRoute .value );
52
+ return activableRoutes .value [index + 1 ] ?? activableRoutes .value [0 ];
53
+ });
54
+
55
+ const prevRoute = computed (() => {
56
+ if (! activeRoute .value ) return ;
57
+ const index = activableRoutes .value .indexOf (activeRoute .value );
58
+ return (
59
+ activableRoutes .value [index - 1 ] ??
60
+ activableRoutes .value [activableRoutes .value .length - 1 ]
61
+ );
62
+ });
63
+
46
64
const { isHover, isFocus, ref : navElement } = NavbarService ;
47
65
48
66
const hasDrawer = computed (() => {
@@ -56,16 +74,50 @@ const showDrawer = computed(() => {
56
74
NavbarService .open .value = show ;
57
75
return show ;
58
76
});
77
+
78
+ const touchStart = ref <TouchEvent >();
79
+
80
+ const onTouchStart = (e : TouchEvent ) => {
81
+ touchStart .value = e ;
82
+ };
83
+
84
+ const onTouchEnd = (e : TouchEvent ) => {
85
+ const _touchStart = touchStart .value ?.targetTouches ?.[0 ];
86
+ const _touchEnd = e .changedTouches ?.[0 ];
87
+ if (! _touchStart ) return ;
88
+ touchStart .value = undefined ;
89
+ const swipe = handleSwipe (_touchStart , _touchEnd , {
90
+ vertical: Header .totalHeight ,
91
+ up: Header .navbarHeight ,
92
+ left: 50 ,
93
+ right: 50 ,
94
+ });
95
+ switch (swipe ) {
96
+ case SwipeDirection .Down :
97
+ isHover .value = true ;
98
+ return swipe ;
99
+ case SwipeDirection .Up :
100
+ isHover .value = false ;
101
+ return swipe ;
102
+ case SwipeDirection .Right :
103
+ return nextRoute .value ? navigate (nextRoute .value ) : undefined ;
104
+ case SwipeDirection .Left :
105
+ return prevRoute .value ? navigate (prevRoute .value ) : undefined ;
106
+ default :
107
+ Logger .warn (' Unknown swipe direction:' , swipe );
108
+ }
109
+ };
59
110
</script >
60
111
61
112
<template >
62
113
<nav
63
114
ref =" navElement"
64
115
@mouseenter =" isHover = true"
65
116
@mouseleave =" isHover = false"
66
- @touchstart =" isHover = true"
67
117
@focusin =" isFocus = true"
68
118
@focusout =" isFocus = false"
119
+ @touchstart =" onTouchStart"
120
+ @touchend =" onTouchEnd"
69
121
>
70
122
<NTabs
71
123
:key =" enabledRoutes.join('-')"
0 commit comments