|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useTranslations } from 'next-intl' |
| 4 | +import { useMemo, useState } from 'react' |
| 5 | +import Footer from '@/components/Footer' |
| 6 | +import Header from '@/components/Header' |
| 7 | +import StackTabs from '@/components/navigation/StackTabs' |
| 8 | +import type { Locale } from '@/i18n/config' |
| 9 | +import { Link } from '@/i18n/navigation' |
| 10 | +import { providersData } from '@/lib/generated' |
| 11 | +import { localizeManifestItems } from '@/lib/manifest-i18n' |
| 12 | +import type { ManifestProvider } from '@/types/manifests' |
| 13 | + |
| 14 | +type Props = { |
| 15 | + locale: string |
| 16 | +} |
| 17 | + |
| 18 | +export default function ModelProvidersPageClient({ locale }: Props) { |
| 19 | + const t = useTranslations('stacksPages.modelProviders') |
| 20 | + const [searchQuery, setSearchQuery] = useState('') |
| 21 | + |
| 22 | + // Localize providers |
| 23 | + const localizedProviders = useMemo(() => { |
| 24 | + return localizeManifestItems( |
| 25 | + providersData as unknown as Record<string, unknown>[], |
| 26 | + locale as Locale |
| 27 | + ) as unknown as ManifestProvider[] |
| 28 | + }, [locale]) |
| 29 | + |
| 30 | + // Filter providers |
| 31 | + const filteredProviders = useMemo(() => { |
| 32 | + let result = [...localizedProviders] |
| 33 | + |
| 34 | + // Apply search filter (search in name and i18n fields) |
| 35 | + if (searchQuery.trim()) { |
| 36 | + const query = searchQuery.toLowerCase() |
| 37 | + result = result.filter(provider => { |
| 38 | + // Search in main name |
| 39 | + if (provider.name.toLowerCase().includes(query)) return true |
| 40 | + // Search in i18n names if available |
| 41 | + if (provider.i18n) { |
| 42 | + return Object.values(provider.i18n).some( |
| 43 | + translation => |
| 44 | + typeof translation === 'object' && |
| 45 | + translation !== null && |
| 46 | + 'name' in translation && |
| 47 | + typeof translation.name === 'string' && |
| 48 | + translation.name.toLowerCase().includes(query) |
| 49 | + ) |
| 50 | + } |
| 51 | + return false |
| 52 | + }) |
| 53 | + } |
| 54 | + |
| 55 | + return result |
| 56 | + }, [localizedProviders, searchQuery]) |
| 57 | + |
| 58 | + const foundationModelProviders = filteredProviders.filter( |
| 59 | + p => p.type === 'foundation-model-provider' |
| 60 | + ) |
| 61 | + const modelServiceProviders = filteredProviders.filter(p => p.type === 'model-service-provider') |
| 62 | + |
| 63 | + return ( |
| 64 | + <> |
| 65 | + <Header /> |
| 66 | + |
| 67 | + <div className="max-w-[1400px] mx-auto px-[var(--spacing-md)] py-[var(--spacing-lg)]"> |
| 68 | + {/* Main Content */} |
| 69 | + <main className="w-full"> |
| 70 | + <div className="mb-[var(--spacing-lg)]"> |
| 71 | + <h1 className="text-[2rem] font-semibold tracking-[-0.03em] mb-[var(--spacing-sm)]"> |
| 72 | + <span className="text-[var(--color-text-muted)] font-light mr-[var(--spacing-xs)]"> |
| 73 | + {'//'} |
| 74 | + </span> |
| 75 | + {t('title')} |
| 76 | + </h1> |
| 77 | + <p className="text-base text-[var(--color-text-secondary)] font-light"> |
| 78 | + {t('subtitle')} |
| 79 | + </p> |
| 80 | + </div> |
| 81 | + |
| 82 | + <StackTabs activeStack="model-providers" locale={locale} /> |
| 83 | + |
| 84 | + {/* Search Box */} |
| 85 | + <div className="mb-[var(--spacing-md)]"> |
| 86 | + <input |
| 87 | + type="text" |
| 88 | + value={searchQuery} |
| 89 | + onChange={e => setSearchQuery(e.target.value)} |
| 90 | + placeholder={t('search') || 'Search by name...'} |
| 91 | + className="w-full max-w-[300px] px-[var(--spacing-sm)] py-1 text-sm border border-[var(--color-border)] bg-[var(--color-background)] text-[var(--color-text)] placeholder:text-[var(--color-text-muted)] focus:outline-none focus:border-[var(--color-border-strong)] transition-colors" |
| 92 | + /> |
| 93 | + </div> |
| 94 | + |
| 95 | + <section className="mb-[var(--spacing-lg)]"> |
| 96 | + <h2 className="text-base uppercase tracking-wide text-[var(--color-text-muted)] mb-[var(--spacing-sm)]"> |
| 97 | + {t('foundationProviders')} |
| 98 | + </h2> |
| 99 | + <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-[var(--spacing-md)]"> |
| 100 | + {foundationModelProviders.map(provider => ( |
| 101 | + <Link |
| 102 | + key={provider.name} |
| 103 | + href={`/${locale}/model-providers/${provider.id}`} |
| 104 | + className="block border border-[var(--color-border)] p-[var(--spacing-md)] hover:border-[var(--color-border-strong)] transition-all hover:-translate-y-0.5 group" |
| 105 | + > |
| 106 | + <div className="flex justify-between items-start mb-[var(--spacing-sm)]"> |
| 107 | + <h3 className="text-lg font-semibold tracking-tight">{provider.name}</h3> |
| 108 | + <span className="text-lg text-[var(--color-text-muted)] group-hover:text-[var(--color-text)] group-hover:translate-x-1 transition-all"> |
| 109 | + → |
| 110 | + </span> |
| 111 | + </div> |
| 112 | + <p className="text-sm leading-relaxed text-[var(--color-text-secondary)] font-light min-h-[4rem]"> |
| 113 | + {provider.description} |
| 114 | + </p> |
| 115 | + </Link> |
| 116 | + ))} |
| 117 | + </div> |
| 118 | + </section> |
| 119 | + |
| 120 | + <section> |
| 121 | + <h2 className="text-base uppercase tracking-wide text-[var(--color-text-muted)] mb-[var(--spacing-sm)]"> |
| 122 | + {t('serviceProviders')} |
| 123 | + </h2> |
| 124 | + <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-[var(--spacing-md)]"> |
| 125 | + {modelServiceProviders.map(provider => ( |
| 126 | + <Link |
| 127 | + key={provider.name} |
| 128 | + href={`/${locale}/model-providers/${provider.id}`} |
| 129 | + className="block border border-[var(--color-border)] p-[var(--spacing-md)] hover:border-[var(--color-border-strong)] transition-all hover:-translate-y-0.5 group" |
| 130 | + > |
| 131 | + <div className="flex justify-between items-start mb-[var(--spacing-sm)]"> |
| 132 | + <h3 className="text-lg font-semibold tracking-tight">{provider.name}</h3> |
| 133 | + <span className="text-lg text-[var(--color-text-muted)] group-hover:text-[var(--color-text)] group-hover:translate-x-1 transition-all"> |
| 134 | + → |
| 135 | + </span> |
| 136 | + </div> |
| 137 | + <p className="text-sm leading-relaxed text-[var(--color-text-secondary)] font-light min-h-[4rem]"> |
| 138 | + {provider.description} |
| 139 | + </p> |
| 140 | + </Link> |
| 141 | + ))} |
| 142 | + </div> |
| 143 | + </section> |
| 144 | + </main> |
| 145 | + </div> |
| 146 | + |
| 147 | + <Footer /> |
| 148 | + </> |
| 149 | + ) |
| 150 | +} |
0 commit comments