|
| 1 | +<script setup lang="ts"> |
| 2 | +interface McpServer { |
| 3 | + title: string |
| 4 | + description: string |
| 5 | + icon: string |
| 6 | + to: string |
| 7 | + category: 'vcs' | 'testing' | 'docs' | 'cloud' |
| 8 | +} |
| 9 | +
|
| 10 | +const props = defineProps<{ |
| 11 | + servers: McpServer[] |
| 12 | + shuffle?: boolean |
| 13 | +}>() |
| 14 | +
|
| 15 | +const categories = { |
| 16 | + vcs: { label: 'Version Control', color: 'var(--color-cat-vcs)' }, |
| 17 | + testing: { label: 'Browser Automation', color: 'var(--color-cat-testing)' }, |
| 18 | + docs: { label: 'Documentation', color: 'var(--color-cat-docs)' }, |
| 19 | + cloud: { label: 'Cloud & DevOps', color: 'var(--color-cat-cloud)' } |
| 20 | +} as const |
| 21 | +
|
| 22 | +const activeFilter = ref<string | null>(null) |
| 23 | +
|
| 24 | +// Shuffle once on component mount to avoid hydration mismatch |
| 25 | +const isReady = ref(!props.shuffle) |
| 26 | +const shuffledServers = ref<McpServer[]>(props.shuffle ? [] : props.servers) |
| 27 | +onMounted(() => { |
| 28 | + if (props.shuffle) { |
| 29 | + // Fisher-Yates shuffle (no built-in in JS/VueUse) |
| 30 | + const arr = [...props.servers] |
| 31 | + for (let i = arr.length - 1; i > 0; i--) { |
| 32 | + const j = Math.floor(Math.random() * (i + 1)) |
| 33 | + ;[arr[i], arr[j]] = [arr[j]!, arr[i]!] |
| 34 | + } |
| 35 | + shuffledServers.value = arr |
| 36 | + isReady.value = true |
| 37 | + } |
| 38 | +}) |
| 39 | +
|
| 40 | +const filteredServers = computed(() => { |
| 41 | + return shuffledServers.value |
| 42 | +}) |
| 43 | +
|
| 44 | +function toggleFilter(categoryId: string) { |
| 45 | + activeFilter.value = activeFilter.value === categoryId ? null : categoryId |
| 46 | +} |
| 47 | +
|
| 48 | +function getCategoryInfo(category: keyof typeof categories) { |
| 49 | + return categories[category] || categories.docs |
| 50 | +} |
| 51 | +
|
| 52 | +function isHighlighted(category: string) { |
| 53 | + return !activeFilter.value || activeFilter.value === category |
| 54 | +} |
| 55 | +</script> |
| 56 | + |
| 57 | +<template> |
| 58 | + <div |
| 59 | + v-if="isReady" |
| 60 | + class="space-y-6" |
| 61 | + > |
| 62 | + <!-- Legend / Filter --> |
| 63 | + <div class="flex flex-wrap gap-2"> |
| 64 | + <button |
| 65 | + v-for="(cat, id) in categories" |
| 66 | + :key="id" |
| 67 | + class="inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-sm font-medium transition-all cursor-pointer border-2" |
| 68 | + :style="{ |
| 69 | + backgroundColor: activeFilter === id ? cat.color : `color-mix(in srgb, ${cat.color} 12%, transparent)`, |
| 70 | + borderColor: cat.color, |
| 71 | + color: activeFilter === id ? 'white' : cat.color |
| 72 | + }" |
| 73 | + @click="toggleFilter(id)" |
| 74 | + > |
| 75 | + <span |
| 76 | + class="w-2.5 h-2.5 rounded-full" |
| 77 | + :style="{ backgroundColor: cat.color }" |
| 78 | + /> |
| 79 | + {{ cat.label }} |
| 80 | + </button> |
| 81 | + <button |
| 82 | + v-if="activeFilter" |
| 83 | + class="px-3 py-1.5 rounded-full text-sm font-medium bg-neutral-500/20 text-neutral-400 hover:bg-neutral-500/30 transition-all cursor-pointer" |
| 84 | + @click="activeFilter = null" |
| 85 | + > |
| 86 | + Show all |
| 87 | + </button> |
| 88 | + </div> |
| 89 | + |
| 90 | + <!-- Grid --> |
| 91 | + <UPageGrid> |
| 92 | + <UPageCard |
| 93 | + v-for="server in filteredServers" |
| 94 | + :key="server.title" |
| 95 | + :title="server.title" |
| 96 | + :description="server.description" |
| 97 | + :icon="server.icon" |
| 98 | + :to="server.to" |
| 99 | + target="_blank" |
| 100 | + :class="[ |
| 101 | + 'transition-all duration-300', |
| 102 | + !isHighlighted(server.category) && 'opacity-25 grayscale scale-95' |
| 103 | + ]" |
| 104 | + :style="{ |
| 105 | + boxShadow: isHighlighted(server.category) |
| 106 | + ? `inset 0 0 0 2px ${getCategoryInfo(server.category).color}, 0 0 20px color-mix(in srgb, ${getCategoryInfo(server.category).color} 25%, transparent)` |
| 107 | + : 'none' |
| 108 | + }" |
| 109 | + :ui="{ |
| 110 | + root: 'relative', |
| 111 | + header: 'absolute top-2 right-2 z-10' |
| 112 | + }" |
| 113 | + > |
| 114 | + <template #header> |
| 115 | + <span |
| 116 | + class="px-2 py-0.5 rounded-full text-xs font-medium" |
| 117 | + :style="{ |
| 118 | + backgroundColor: `color-mix(in srgb, ${getCategoryInfo(server.category).color} 19%, transparent)`, |
| 119 | + color: getCategoryInfo(server.category).color |
| 120 | + }" |
| 121 | + > |
| 122 | + {{ getCategoryInfo(server.category).label }} |
| 123 | + </span> |
| 124 | + </template> |
| 125 | + </UPageCard> |
| 126 | + </UPageGrid> |
| 127 | + </div> |
| 128 | +</template> |
0 commit comments