|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, onMounted } from 'vue' |
| 3 | +import { useI18n } from 'vue-i18n' |
| 4 | +import { useRouter } from 'vue-router' |
| 5 | +import { Button } from '@/components/ui/button' |
| 6 | +import { Skeleton } from '@/components/ui/skeleton' |
| 7 | +import { Layers } from 'lucide-vue-next' |
| 8 | +import { McpCatalogService } from '@/services/mcpCatalogService' |
| 9 | +import type { McpServer } from '@/views/admin/mcp-server-catalog/types' |
| 10 | +import McpServerAvatar from './McpServerAvatar.vue' |
| 11 | +
|
| 12 | +interface Props { |
| 13 | + limit?: number |
| 14 | +} |
| 15 | +
|
| 16 | +const props = withDefaults(defineProps<Props>(), { |
| 17 | + limit: 8 |
| 18 | +}) |
| 19 | +
|
| 20 | +const { t } = useI18n() |
| 21 | +const router = useRouter() |
| 22 | +
|
| 23 | +const featuredServers = ref<McpServer[]>([]) |
| 24 | +const isLoading = ref(true) |
| 25 | +const error = ref<string | null>(null) |
| 26 | +
|
| 27 | +const fetchFeaturedServers = async () => { |
| 28 | + try { |
| 29 | + isLoading.value = true |
| 30 | + error.value = null |
| 31 | +
|
| 32 | + const response = await McpCatalogService.getGlobalServersPaginated( |
| 33 | + { featured: true }, |
| 34 | + { limit: props.limit, offset: 0 } |
| 35 | + ) |
| 36 | +
|
| 37 | + featuredServers.value = response.items |
| 38 | + } catch (err) { |
| 39 | + console.error('Error fetching featured servers:', err) |
| 40 | + error.value = err instanceof Error ? err.message : 'Failed to load featured servers' |
| 41 | + featuredServers.value = [] |
| 42 | + } finally { |
| 43 | + isLoading.value = false |
| 44 | + } |
| 45 | +} |
| 46 | +
|
| 47 | +const handleServerClick = (server: McpServer) => { |
| 48 | + router.push(`/mcp-server/install/${server.id}`) |
| 49 | +} |
| 50 | +
|
| 51 | +const handleBrowseCatalog = () => { |
| 52 | + router.push('/mcp-server/search') |
| 53 | +} |
| 54 | +
|
| 55 | +const truncateDescription = (description: string | null | undefined, maxLength: number = 80) => { |
| 56 | + if (!description) return 'No description available' |
| 57 | + if (description.length <= maxLength) return description |
| 58 | + return description.substring(0, maxLength) + '...' |
| 59 | +} |
| 60 | +
|
| 61 | +onMounted(() => { |
| 62 | + fetchFeaturedServers() |
| 63 | +}) |
| 64 | +</script> |
| 65 | + |
| 66 | +<template> |
| 67 | + <div class="flex flex-col items-center justify-start gap-6 p-6 border border-solid rounded-lg"> |
| 68 | + <Layers class="h-5 w-5 text-muted-foreground" /> |
| 69 | + |
| 70 | + <p class="text-base font-medium text-center"> |
| 71 | + {{ t('mcpInstallations.featuredList.title') }} |
| 72 | + </p> |
| 73 | + |
| 74 | + <div v-if="isLoading" class="flex flex-col items-stretch justify-start gap-4 w-full"> |
| 75 | + <div v-for="i in 5" :key="i" class="flex flex-row items-center gap-3"> |
| 76 | + <Skeleton class="h-9 w-9 rounded-md" /> |
| 77 | + <div class="flex flex-col gap-1 flex-1"> |
| 78 | + <Skeleton class="h-4 w-32" /> |
| 79 | + <Skeleton class="h-3 w-full" /> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + |
| 84 | + <div v-else-if="error" class="text-center py-4"> |
| 85 | + <p class="text-sm text-destructive">{{ error }}</p> |
| 86 | + <Button |
| 87 | + variant="outline" |
| 88 | + size="sm" |
| 89 | + @click="fetchFeaturedServers" |
| 90 | + class="mt-2" |
| 91 | + > |
| 92 | + {{ t('actions.retry') }} |
| 93 | + </Button> |
| 94 | + </div> |
| 95 | + |
| 96 | + <div v-else-if="featuredServers.length === 0" class="text-center py-4"> |
| 97 | + <p class="text-sm text-muted-foreground"> |
| 98 | + {{ t('mcpInstallations.featured.noServers') }} |
| 99 | + </p> |
| 100 | + </div> |
| 101 | + |
| 102 | + <div v-else class="flex flex-col items-stretch justify-start gap-4 w-full"> |
| 103 | + <button |
| 104 | + v-for="server in featuredServers" |
| 105 | + :key="server.id" |
| 106 | + type="button" |
| 107 | + @click="handleServerClick(server)" |
| 108 | + class="flex flex-row items-start gap-3 text-left hover:bg-muted/50 rounded-md p-2 -mx-2 transition-colors" |
| 109 | + > |
| 110 | + <McpServerAvatar |
| 111 | + :icon-url="server.icon_url" |
| 112 | + :server-name="server.name" |
| 113 | + size="sm" |
| 114 | + rounded="md" |
| 115 | + class="shrink-0" |
| 116 | + /> |
| 117 | + <div class="flex flex-col items-stretch justify-start min-w-0"> |
| 118 | + <p class="text-sm font-medium truncate">{{ server.name }}</p> |
| 119 | + <p class="text-xs text-muted-foreground line-clamp-2"> |
| 120 | + {{ truncateDescription(server.description) }} |
| 121 | + </p> |
| 122 | + </div> |
| 123 | + </button> |
| 124 | + </div> |
| 125 | + |
| 126 | + <div class="w-full border-t border-border" /> |
| 127 | + |
| 128 | + <Button |
| 129 | + variant="outline" |
| 130 | + @click="handleBrowseCatalog" |
| 131 | + class="w-full" |
| 132 | + > |
| 133 | + {{ t('mcpInstallations.featuredList.browseCatalog') }} |
| 134 | + </Button> |
| 135 | + </div> |
| 136 | +</template> |
| 137 | + |
| 138 | +<style scoped> |
| 139 | +.line-clamp-2 { |
| 140 | + display: -webkit-box; |
| 141 | + -webkit-line-clamp: 2; |
| 142 | + -webkit-box-orient: vertical; |
| 143 | + overflow: hidden; |
| 144 | +} |
| 145 | +</style> |
0 commit comments