|
| 1 | +<script setup lang="ts"> |
| 2 | +const props = defineProps<{ |
| 3 | + username: string |
| 4 | +}>() |
| 5 | +
|
| 6 | +const { listUserOrgs } = useConnector() |
| 7 | +
|
| 8 | +const isOpen = ref(false) |
| 9 | +const isLoading = ref(false) |
| 10 | +const orgs = ref<string[]>([]) |
| 11 | +const hasLoaded = ref(false) |
| 12 | +const error = ref<string | null>(null) |
| 13 | +
|
| 14 | +async function loadOrgs() { |
| 15 | + if (hasLoaded.value || isLoading.value) return |
| 16 | +
|
| 17 | + isLoading.value = true |
| 18 | + error.value = null |
| 19 | + try { |
| 20 | + const orgList = await listUserOrgs() |
| 21 | + if (orgList) { |
| 22 | + // Already sorted alphabetically by server, take top 10 |
| 23 | + orgs.value = orgList.slice(0, 10) |
| 24 | + } else { |
| 25 | + error.value = 'Failed to load organizations' |
| 26 | + } |
| 27 | + hasLoaded.value = true |
| 28 | + } catch { |
| 29 | + error.value = 'Failed to load organizations' |
| 30 | + } finally { |
| 31 | + isLoading.value = false |
| 32 | + } |
| 33 | +} |
| 34 | +
|
| 35 | +function handleMouseEnter() { |
| 36 | + isOpen.value = true |
| 37 | + if (!hasLoaded.value) { |
| 38 | + loadOrgs() |
| 39 | + } |
| 40 | +} |
| 41 | +
|
| 42 | +function handleMouseLeave() { |
| 43 | + isOpen.value = false |
| 44 | +} |
| 45 | +
|
| 46 | +function handleKeydown(event: KeyboardEvent) { |
| 47 | + if (event.key === 'Escape' && isOpen.value) { |
| 48 | + isOpen.value = false |
| 49 | + } |
| 50 | +} |
| 51 | +</script> |
| 52 | + |
| 53 | +<template> |
| 54 | + <div |
| 55 | + class="relative" |
| 56 | + @mouseenter="handleMouseEnter" |
| 57 | + @mouseleave="handleMouseLeave" |
| 58 | + @keydown="handleKeydown" |
| 59 | + > |
| 60 | + <NuxtLink |
| 61 | + :to="`/~${username}/orgs`" |
| 62 | + class="link-subtle font-mono text-sm inline-flex items-center gap-1" |
| 63 | + > |
| 64 | + orgs |
| 65 | + <span |
| 66 | + class="i-carbon-chevron-down w-3 h-3 transition-transform duration-200" |
| 67 | + :class="{ 'rotate-180': isOpen }" |
| 68 | + aria-hidden="true" |
| 69 | + /> |
| 70 | + </NuxtLink> |
| 71 | + |
| 72 | + <Transition |
| 73 | + enter-active-class="transition-all duration-150" |
| 74 | + leave-active-class="transition-all duration-100" |
| 75 | + enter-from-class="opacity-0 translate-y-1" |
| 76 | + leave-to-class="opacity-0 translate-y-1" |
| 77 | + > |
| 78 | + <div v-if="isOpen" class="absolute right-0 top-full pt-2 w-56 z-50"> |
| 79 | + <div class="bg-bg-elevated border border-border rounded-lg shadow-lg overflow-hidden"> |
| 80 | + <div class="px-3 py-2 border-b border-border"> |
| 81 | + <span class="font-mono text-xs text-fg-subtle">Your Organizations</span> |
| 82 | + </div> |
| 83 | + |
| 84 | + <div v-if="isLoading" class="px-3 py-4 text-center"> |
| 85 | + <span class="text-fg-muted text-sm">Loading…</span> |
| 86 | + </div> |
| 87 | + |
| 88 | + <div v-else-if="error" class="px-3 py-4 text-center"> |
| 89 | + <span class="text-fg-muted text-sm">{{ error }}</span> |
| 90 | + </div> |
| 91 | + |
| 92 | + <ul v-else-if="orgs.length > 0" class="py-1 max-h-80 overflow-y-auto"> |
| 93 | + <li v-for="org in orgs" :key="org"> |
| 94 | + <NuxtLink |
| 95 | + :to="`/@${org}`" |
| 96 | + class="block px-3 py-2 font-mono text-sm text-fg hover:bg-bg-subtle transition-colors" |
| 97 | + > |
| 98 | + @{{ org }} |
| 99 | + </NuxtLink> |
| 100 | + </li> |
| 101 | + </ul> |
| 102 | + |
| 103 | + <div v-else class="px-3 py-4 text-center"> |
| 104 | + <span class="text-fg-muted text-sm">No organizations found</span> |
| 105 | + </div> |
| 106 | + |
| 107 | + <div class="px-3 py-2 border-t border-border"> |
| 108 | + <NuxtLink |
| 109 | + :to="`/~${username}/orgs`" |
| 110 | + class="link-subtle font-mono text-xs inline-flex items-center gap-1" |
| 111 | + > |
| 112 | + View all |
| 113 | + <span class="i-carbon-arrow-right w-3 h-3" aria-hidden="true" /> |
| 114 | + </NuxtLink> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + </div> |
| 118 | + </Transition> |
| 119 | + </div> |
| 120 | +</template> |
0 commit comments