-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Navbar.vue
205 lines (194 loc) · 5.7 KB
/
Navbar.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<template>
<nav class="sticky top-0 z-50 flex-none">
<div
class="
w-full
flex flex-row flex-wrap
items-center
justify-between
bg-white
px-6
border-b border-gray-300
h-20
"
>
<div class="flex">
<!-- Hamburger icon for small screens -->
<div class="flex md:hidden mr-5 items-center">
<button id="sidebarToggle" class="text-right text-gray-900 h-6 w-6">
<FontAwesomeIcon icon="list-ul" />
</button>
</div>
<!-- Search bar -->
<div class="relative text-gray-600">
<t-input
v-model="searchQuery"
type="search"
placeholder="Search..."
class="
w-full
xl:w-96
px-5
border-none
shadow-none
pl-10
font-semibold
text-lg
"
/>
<button type="submit" class="absolute left-0 top-0 bottom-0 ml-2">
<FontAwesomeIcon icon="search" class="text-gray-400" />
</button>
</div>
</div>
<!-- Main menu -->
<div class="space-x-14">
<span class="text-primary-600 text-lg font-semibold">Library</span>
<span class="text-gray-400 text-lg font-semibold">Browse</span>
<div class="inline">
<span class="text-gray-400 text-lg font-semibold">
Subscriptions
</span>
<div class="inline-block align-top pl-0.5 -mt-1">
<FontAwesomeIcon icon="circle" class="text-primary-600" size="xs" />
</div>
</div>
</div>
<!-- User profile -->
<div class="flex items-center pr-10 space-x-7">
<FontAwesomeIcon
icon="bell"
class="text-gray-400 hover:text-highlight-500"
size="lg"
/>
<div>
<!-- User profile dropdown -->
<t-dropdown variant="left">
<div
slot="trigger"
slot-scope="{
mousedownHandler,
focusHandler,
blurHandler,
keydownHandler,
}"
>
<button
id="user-menu"
class="w-12 h-12"
aria-label="User menu"
aria-haspopup="true"
@mousedown="mousedownHandler"
@focus="focusHandler"
@blur="blurHandler"
@keydown="keydownHandler"
>
<img
class="rounded-full"
src="https://a7sas.net/wp-content/uploads/2019/07/4060.jpeg"
alt=""
/>
</button>
</div>
<div slot-scope="{ blurHandler }" class="w-36">
<button
class="
block
w-full
px-4
py-2
text-sm
leading-5
text-gray-700
transition
duration-150
ease-in-out
hover:bg-gray-100
focus:outline-none focus:bg-gray-100
"
role="menuitem"
@blur="blurHandler"
>
Your Profile
</button>
<button
class="
block
w-full
px-4
py-2
text-sm
leading-5
text-gray-700
transition
duration-150
ease-in-out
hover:bg-gray-100
focus:outline-none focus:bg-gray-100
"
role="menuitem"
@blur="blurHandler"
>
Settings
</button>
<button
class="
block
w-full
px-4
py-2
text-sm
leading-5
text-gray-700
transition
duration-150
ease-in-out
border-t
hover:bg-gray-100
focus:outline-none focus:bg-gray-100
"
@click="logout"
>
Logout
</button>
</div>
</t-dropdown>
</div>
</div>
</div>
</nav>
</template>
<script lang="ts">
import { useApolloClient, useMutation } from '@vue/apollo-composable'
import { gql } from '@apollo/client/core'
import { defineComponent, useRouter, ref, watch } from '@nuxtjs/composition-api'
import { LogoutDocument } from '~/apollo/graphql'
import { currentUserVar } from '~/apollo/cache'
import { useUiStore } from '~/store'
export default defineComponent({
setup() {
const { resolveClient } = useApolloClient()
gql`
mutation logout {
logout
}
`
const { mutate: logout, onDone } = useMutation(LogoutDocument)
const router = useRouter()
onDone(() => {
// Reset graphql cache
void resolveClient().clearStore()
currentUserVar(null)
void router.push({ name: 'index' })
})
const uiStore = useUiStore()
// TODO:Don't update store immediately to avoid unnecessary queries to the server.
// For some reason `toRef(uiStore.activeSearchQuery) + useDebounce` or `debouncedWatch` doesn't work here
const searchQuery = ref(uiStore.activeSearchQuery ?? '')
watch(searchQuery, (newQuery) => {
uiStore.activeSearchQuery = newQuery
})
return { logout, searchQuery }
},
})
</script>