-
-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathAccountMenu.client.vue
More file actions
340 lines (311 loc) · 11.7 KB
/
AccountMenu.client.vue
File metadata and controls
340 lines (311 loc) · 11.7 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<script setup lang="ts">
import { useAtproto } from '~/composables/atproto/useAtproto'
import { useModal } from '~/composables/useModal'
const {
isConnected: isNpmConnected,
isConnecting: isNpmConnecting,
npmUser,
avatar: npmAvatar,
activeOperations,
hasPendingOperations,
} = useConnector()
const { user: atprotoUser } = useAtproto()
const { isConnected: isGitHubConnected, user: githubUser } = useGitHub()
const isOpen = shallowRef(false)
/** Check if connected to at least one service */
const hasAnyConnection = computed(
() => isNpmConnected.value || !!atprotoUser.value || isGitHubConnected.value,
)
/** Count of connected services for avatar stacking */
const connectedCount = computed(() => {
let count = 0
if (isNpmConnected.value) count++
if (atprotoUser.value) count++
if (isGitHubConnected.value) count++
return count
})
/** Check if connected to more than one service */
const hasMultipleConnections = computed(() => connectedCount.value > 1)
/** Only show count of active (pending/approved/running) operations */
const operationCount = computed(() => activeOperations.value.length)
const accountMenuRef = useTemplateRef('accountMenuRef')
onClickOutside(accountMenuRef, () => {
isOpen.value = false
})
useEventListener('keydown', event => {
if (event.key === 'Escape' && isOpen.value) {
isOpen.value = false
}
})
const connectorModal = useModal('connector-modal')
function openConnectorModal() {
if (connectorModal) {
isOpen.value = false
connectorModal.open()
}
}
const atprotoModal = useModal('atproto-modal')
function openAtprotoModal() {
if (atprotoModal) {
isOpen.value = false
atprotoModal.open()
}
}
const githubModal = useModal('github-modal')
function openGitHubModal() {
if (githubModal) {
isOpen.value = false
githubModal.open()
}
}
</script>
<template>
<div ref="accountMenuRef" class="relative flex min-w-28 justify-end">
<ButtonBase
type="button"
:aria-expanded="isOpen"
aria-haspopup="true"
@click="isOpen = !isOpen"
class="border-none"
>
<!-- Stacked avatars when connected -->
<span
v-if="hasAnyConnection"
class="flex items-center"
:class="hasMultipleConnections ? '-space-x-2' : ''"
>
<!-- npm avatar (first/back) -->
<img
v-if="isNpmConnected && npmAvatar"
:src="npmAvatar"
:alt="npmUser || $t('account_menu.npm_cli')"
width="24"
height="24"
class="w-6 h-6 rounded-full ring-2 ring-bg object-cover"
/>
<span
v-else-if="isNpmConnected"
class="w-6 h-6 rounded-full bg-bg-muted ring-2 ring-bg flex items-center justify-center"
>
<span class="i-lucide:terminal w-3 h-3 text-fg-muted" aria-hidden="true" />
</span>
<!-- Atmosphere avatar (second/front, overlapping) -->
<img
v-if="atprotoUser?.avatar"
:src="atprotoUser.avatar"
:alt="atprotoUser.handle"
width="24"
height="24"
class="w-6 h-6 rounded-full ring-2 ring-bg object-cover"
:class="hasMultipleConnections ? 'relative z-10' : ''"
/>
<span
v-else-if="atprotoUser"
class="w-6 h-6 rounded-full bg-bg-muted ring-2 ring-bg flex items-center justify-center"
:class="hasMultipleConnections ? 'relative z-10' : ''"
>
<span class="i-lucide:at-sign w-3 h-3 text-fg-muted" aria-hidden="true" />
</span>
<!-- GitHub avatar (overlapping) -->
<span
v-if="isGitHubConnected"
class="w-6 h-6 rounded-full bg-bg-muted ring-2 ring-bg flex items-center justify-center"
:class="hasMultipleConnections ? 'relative z-20' : ''"
>
<span class="i-simple-icons:github w-3 h-3 text-fg-muted" aria-hidden="true" />
</span>
</span>
<!-- "connect" text when not connected -->
<span v-if="!hasAnyConnection" class="font-mono text-sm">
{{ $t('account_menu.connect') }}
</span>
<!-- Chevron -->
<span
class="i-lucide:chevron-down w-3 h-3 transition-transform duration-200"
:class="{ 'rotate-180': isOpen }"
aria-hidden="true"
/>
<!-- Operation count badge (when npm connected with pending ops) -->
<span
v-if="isNpmConnected && operationCount > 0"
class="absolute -top-1 -inset-ie-1 min-w-[1rem] h-4 px-1 flex items-center justify-center font-mono text-3xs rounded-full"
:class="hasPendingOperations ? 'bg-yellow-500 text-black' : 'bg-blue-500 text-white'"
aria-hidden="true"
>
{{ operationCount }}
</span>
</ButtonBase>
<!-- Dropdown menu -->
<Transition
enter-active-class="transition-all duration-150"
leave-active-class="transition-all duration-100"
enter-from-class="opacity-0 translate-y-1"
leave-to-class="opacity-0 translate-y-1"
>
<div v-if="isOpen" class="absolute inset-ie-0 top-full pt-2 w-72 z-50" role="menu">
<div
class="bg-bg-subtle/80 backdrop-blur-sm border border-border-subtle rounded-lg shadow-lg shadow-bg-elevated/50 overflow-hidden px-1"
>
<!-- Connected accounts section -->
<div v-if="hasAnyConnection" class="py-1">
<!-- npm CLI connection -->
<ButtonBase
v-if="isNpmConnected && npmUser"
role="menuitem"
class="w-full text-start gap-x-3 border-none"
@click="openConnectorModal"
out
>
<img
v-if="npmAvatar"
:src="npmAvatar"
:alt="npmUser"
width="32"
height="32"
class="w-8 h-8 rounded-full object-cover"
/>
<span
v-else
class="w-8 h-8 rounded-full bg-bg-muted flex items-center justify-center"
>
<span class="i-lucide:terminal w-4 h-4 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1 min-w-0">
<span class="font-mono text-sm text-fg truncate block">~{{ npmUser }}</span>
<span class="text-xs text-fg-subtle">{{ $t('account_menu.npm_cli') }}</span>
</span>
<span
v-if="operationCount > 0"
class="px-1.5 py-0.5 font-mono text-xs rounded"
:class="
hasPendingOperations
? 'bg-yellow-500/20 text-yellow-600'
: 'bg-blue-500/20 text-blue-500'
"
>
{{
$t('account_menu.ops', {
count: operationCount,
})
}}
</span>
</ButtonBase>
<!-- Atmosphere connection -->
<ButtonBase
v-if="atprotoUser"
role="menuitem"
class="w-full text-start gap-x-3 border-none"
@click="openAtprotoModal"
>
<img
v-if="atprotoUser.avatar"
:src="atprotoUser.avatar"
:alt="atprotoUser.handle"
width="32"
height="32"
class="w-8 h-8 rounded-full object-cover"
/>
<span
v-else
class="w-8 h-8 rounded-full bg-bg-muted flex items-center justify-center"
>
<span class="i-lucide:at-sign w-4 h-4 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1 min-w-0">
<span class="font-mono text-sm text-fg truncate block"
>@{{ atprotoUser.handle }}</span
>
<span class="text-xs text-fg-subtle">{{ $t('account_menu.atmosphere') }}</span>
</span>
</ButtonBase>
<!-- GitHub connection -->
<ButtonBase
v-if="isGitHubConnected && githubUser"
role="menuitem"
class="w-full text-start gap-x-3 border-none"
@click="openGitHubModal"
>
<span class="w-8 h-8 rounded-full bg-bg-muted flex items-center justify-center">
<span class="i-simple-icons:github w-4 h-4 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1 min-w-0">
<span class="font-mono text-sm text-fg truncate block">{{
githubUser.username
}}</span>
<span class="text-xs text-fg-subtle">{{ $t('account_menu.github') }}</span>
</span>
</ButtonBase>
</div>
<!-- Divider (only if we have connections AND options to connect) -->
<div
v-if="hasAnyConnection && (!isNpmConnected || !atprotoUser || !isGitHubConnected)"
class="border-t border-border"
/>
<!-- Connect options -->
<div v-if="!isNpmConnected || !atprotoUser || !isGitHubConnected" class="py-1">
<ButtonBase
v-if="!isNpmConnected"
role="menuitem"
class="w-full text-start gap-x-3 border-none"
@click="openConnectorModal"
>
<span class="w-8 h-8 rounded-full bg-bg-muted flex items-center justify-center">
<span
v-if="isNpmConnecting"
class="i-svg-spinners:ring-resize w-4 h-4 text-yellow-500 animate-spin"
aria-hidden="true"
/>
<span v-else class="i-lucide:terminal w-4 h-4 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1 min-w-0">
<span class="font-mono text-sm text-fg block">
{{
isNpmConnecting
? $t('account_menu.connecting')
: $t('account_menu.connect_npm_cli')
}}
</span>
<span class="text-xs text-fg-subtle">{{ $t('account_menu.npm_cli_desc') }}</span>
</span>
</ButtonBase>
<ButtonBase
v-if="!atprotoUser"
role="menuitem"
class="w-full text-start gap-x-3 border-none"
@click="openAtprotoModal"
>
<span class="w-8 h-8 rounded-full bg-bg-muted flex items-center justify-center">
<span class="i-lucide:at-sign w-4 h-4 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1 min-w-0">
<span class="font-mono text-sm text-fg block">
{{ $t('account_menu.connect_atmosphere') }}
</span>
<span class="text-xs text-fg-subtle">{{ $t('account_menu.atmosphere_desc') }}</span>
</span>
</ButtonBase>
<ButtonBase
v-if="!isGitHubConnected"
role="menuitem"
class="w-full text-start gap-x-3 border-none"
@click="openGitHubModal"
>
<span class="w-8 h-8 rounded-full bg-bg-muted flex items-center justify-center">
<span class="i-simple-icons:github w-4 h-4 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1 min-w-0">
<span class="font-mono text-sm text-fg block">
{{ $t('account_menu.connect_github') }}
</span>
<span class="text-xs text-fg-subtle">{{ $t('account_menu.github_desc') }}</span>
</span>
</ButtonBase>
</div>
</div>
</div>
</Transition>
</div>
<HeaderConnectorModal />
<HeaderAtprotoModal />
<HeaderGitHubModal />
</template>