feat: update homepage to use real database data
- Add server component to fetch live stats from database - Tool count from Tool table - Invocations from successful Simulation records - Average latency from recent executions - Category distribution stats - Add featured tools section - Display top 6 tools by quality score - Show tool cards with name, description, category, tags - Include quality score and download metrics - Official badge for verified tools - Click-through to tool detail pages - Update HeroSection component - Accept stats prop with real database metrics - Format large numbers (e.g., "1.2K", "5.3M") - Add functional search navigation - Enter key and button click navigate to tool-search - Empty search browses all tools - Optimize database queries - Use Promise.all() for parallel execution - Calculate avg latency from last 100 simulations - Graceful error handling with fallback values 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
1cdbf8c891
commit
59da95ce85
2 changed files with 192 additions and 45 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { prisma } from '@tpmjs/db';
|
||||
import { Badge } from '@tpmjs/ui/Badge/Badge';
|
||||
import { Button } from '@tpmjs/ui/Button/Button';
|
||||
import { Container } from '@tpmjs/ui/Container/Container';
|
||||
import { Header } from '@tpmjs/ui/Header/Header';
|
||||
|
|
@ -5,7 +7,90 @@ import Link from 'next/link';
|
|||
import { ThemeToggle } from '../components/ThemeToggle';
|
||||
import { HeroSection } from '../components/home/HeroSection';
|
||||
|
||||
export default function HomePage(): React.ReactElement {
|
||||
async function getHomePageData() {
|
||||
try {
|
||||
// Fetch stats in parallel
|
||||
const [toolCount, simulationCount, featuredTools, categoryStats] = await Promise.all([
|
||||
// Total tool count
|
||||
prisma.tool.count(),
|
||||
|
||||
// Total successful simulations (as proxy for invocations)
|
||||
prisma.simulation.count({
|
||||
where: { status: 'success' },
|
||||
}),
|
||||
|
||||
// Top 6 featured tools by quality score
|
||||
prisma.tool.findMany({
|
||||
orderBy: [{ qualityScore: 'desc' }, { npmDownloadsLastMonth: 'desc' }],
|
||||
take: 6,
|
||||
select: {
|
||||
id: true,
|
||||
npmPackageName: true,
|
||||
description: true,
|
||||
category: true,
|
||||
tags: true,
|
||||
qualityScore: true,
|
||||
npmDownloadsLastMonth: true,
|
||||
isOfficial: true,
|
||||
},
|
||||
}),
|
||||
|
||||
// Category distribution for stats
|
||||
prisma.tool.groupBy({
|
||||
by: ['category'],
|
||||
_count: true,
|
||||
}),
|
||||
]);
|
||||
|
||||
// Calculate average latency from recent successful simulations
|
||||
const recentSimulations = await prisma.simulation.findMany({
|
||||
where: {
|
||||
status: 'success',
|
||||
executionTimeMs: { not: null },
|
||||
},
|
||||
select: { executionTimeMs: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 100,
|
||||
});
|
||||
|
||||
const avgLatency =
|
||||
recentSimulations.length > 0
|
||||
? Math.round(
|
||||
recentSimulations.reduce((sum, s) => sum + (s.executionTimeMs || 0), 0) /
|
||||
recentSimulations.length
|
||||
)
|
||||
: 0;
|
||||
|
||||
return {
|
||||
stats: {
|
||||
toolCount,
|
||||
invocations: simulationCount,
|
||||
avgLatency,
|
||||
categoryCount: categoryStats.length,
|
||||
},
|
||||
featuredTools,
|
||||
categories: categoryStats.slice(0, 5).map((c) => ({
|
||||
name: c.category,
|
||||
count: c._count,
|
||||
})),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch homepage data:', error);
|
||||
return {
|
||||
stats: {
|
||||
toolCount: 0,
|
||||
invocations: 0,
|
||||
avgLatency: 0,
|
||||
categoryCount: 0,
|
||||
},
|
||||
featuredTools: [],
|
||||
categories: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default async function HomePage(): Promise<React.ReactElement> {
|
||||
const data = await getHomePageData();
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col">
|
||||
{/* Header */}
|
||||
|
|
@ -48,61 +133,83 @@ export default function HomePage(): React.ReactElement {
|
|||
|
||||
<main className="flex-1">
|
||||
{/* Hero Section - Dithered Design */}
|
||||
<HeroSection />
|
||||
<HeroSection stats={data.stats} />
|
||||
|
||||
{/* Featured Tools Section */}
|
||||
<section className="py-16 bg-background">
|
||||
<Container size="xl" padding="lg">
|
||||
<div className="text-center mb-12">
|
||||
<h2 className="text-3xl md:text-4xl font-bold mb-4 text-foreground">
|
||||
Discover AI Tools
|
||||
Featured Tools
|
||||
</h2>
|
||||
<p className="text-lg text-foreground-secondary max-w-2xl mx-auto mb-8">
|
||||
Browse our collection of AI-ready tools. Search, filter, and integrate the perfect
|
||||
tools for your AI agents.
|
||||
Top-rated tools from our registry. Sorted by quality score and community adoption.
|
||||
</p>
|
||||
<div className="flex flex-col sm:flex-row gap-4 justify-center items-center">
|
||||
<Link href="/tool/tool-search">
|
||||
<Button size="lg" variant="default">
|
||||
Browse All Tools
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/tool/tool-search">
|
||||
<Button size="lg" variant="outline">
|
||||
Search Tools
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-8 mt-12">
|
||||
{/* Feature cards */}
|
||||
<div className="p-6 border border-border rounded-lg bg-surface">
|
||||
<div className="text-4xl mb-4">🔍</div>
|
||||
<h3 className="text-xl font-semibold mb-2 text-foreground">Smart Search</h3>
|
||||
<p className="text-foreground-secondary">
|
||||
Find tools by name, category, tags, or functionality. Advanced filters help you
|
||||
discover exactly what you need.
|
||||
</p>
|
||||
</div>
|
||||
{data.featuredTools.length > 0 ? (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-12">
|
||||
{data.featuredTools.map((tool) => (
|
||||
<Link key={tool.id} href={`/tool/${tool.npmPackageName}`} className="group">
|
||||
<div className="p-6 border border-border rounded-lg bg-surface hover:border-foreground transition-colors h-full flex flex-col">
|
||||
<div className="flex items-start justify-between mb-3">
|
||||
<h3 className="text-lg font-semibold text-foreground group-hover:text-brutalist-accent transition-colors">
|
||||
{tool.npmPackageName}
|
||||
</h3>
|
||||
{tool.isOfficial && (
|
||||
<Badge variant="default" size="sm">
|
||||
Official
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="p-6 border border-border rounded-lg bg-surface">
|
||||
<div className="text-4xl mb-4">⚡</div>
|
||||
<h3 className="text-xl font-semibold mb-2 text-foreground">Quality Metrics</h3>
|
||||
<p className="text-foreground-secondary">
|
||||
Every tool includes quality scores, download stats, and community feedback to help
|
||||
you choose wisely.
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-sm text-foreground-secondary mb-4 flex-1 line-clamp-3">
|
||||
{tool.description}
|
||||
</p>
|
||||
|
||||
<div className="p-6 border border-border rounded-lg bg-surface">
|
||||
<div className="text-4xl mb-4">🤖</div>
|
||||
<h3 className="text-xl font-semibold mb-2 text-foreground">AI Agent Ready</h3>
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<Badge variant="outline" size="sm">
|
||||
{tool.category}
|
||||
</Badge>
|
||||
{tool.tags.slice(0, 2).map((tag) => (
|
||||
<Badge key={tag} variant="secondary" size="sm">
|
||||
{tag}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-4 pt-4 border-t border-border flex items-center justify-between text-xs text-foreground-tertiary">
|
||||
<span>
|
||||
Quality:{' '}
|
||||
{tool.qualityScore ? Number(tool.qualityScore).toFixed(2) : 'N/A'}
|
||||
</span>
|
||||
<span>
|
||||
{tool.npmDownloadsLastMonth?.toLocaleString() || '0'} downloads/mo
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-12">
|
||||
<p className="text-foreground-secondary">
|
||||
All tools include AI agent integration guides, parameter specs, and usage
|
||||
examples.
|
||||
No tools available yet. Check back soon!
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col sm:flex-row gap-4 justify-center items-center">
|
||||
<Link href="/tool/tool-search">
|
||||
<Button size="lg" variant="default">
|
||||
Browse All {data.stats.toolCount} Tools
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/tool/tool-search">
|
||||
<Button size="lg" variant="outline">
|
||||
Search by Category
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</Container>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -2,10 +2,45 @@
|
|||
|
||||
import { Button } from '@tpmjs/ui/Button/Button';
|
||||
import { Input } from '@tpmjs/ui/Input/Input';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
|
||||
export function HeroSection(): React.ReactElement {
|
||||
interface HeroSectionProps {
|
||||
stats: {
|
||||
toolCount: number;
|
||||
invocations: number;
|
||||
avgLatency: number;
|
||||
categoryCount: number;
|
||||
};
|
||||
}
|
||||
|
||||
function formatNumber(num: number): string {
|
||||
if (num >= 1000000) {
|
||||
return `${(num / 1000000).toFixed(1)}M`;
|
||||
}
|
||||
if (num >= 1000) {
|
||||
return `${(num / 1000).toFixed(1)}K`;
|
||||
}
|
||||
return num.toString();
|
||||
}
|
||||
|
||||
export function HeroSection({ stats }: HeroSectionProps): React.ReactElement {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const router = useRouter();
|
||||
|
||||
const handleSearch = () => {
|
||||
if (searchQuery.trim()) {
|
||||
router.push(`/tool/tool-search?q=${encodeURIComponent(searchQuery)}`);
|
||||
} else {
|
||||
router.push('/tool/tool-search');
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleSearch();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="relative min-h-[90vh] overflow-hidden bg-background">
|
||||
|
|
@ -37,18 +72,21 @@ export function HeroSection(): React.ReactElement {
|
|||
{/* Live Metrics Strip */}
|
||||
<div className="mb-12 flex flex-wrap items-center gap-3 border-l-[6px] border-brutalist-accent pl-6 font-mono text-base md:text-lg font-bold uppercase tracking-wider">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-foreground">2,847</span>
|
||||
<span className="text-foreground">{formatNumber(stats.toolCount)}</span>
|
||||
<span className="text-foreground-secondary">TOOLS</span>
|
||||
</div>
|
||||
<span className="text-foreground-tertiary">/</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-foreground">12M+</span>
|
||||
<span className="text-foreground">
|
||||
{formatNumber(stats.invocations)}
|
||||
{stats.invocations >= 1000 ? '+' : ''}
|
||||
</span>
|
||||
<span className="text-foreground-secondary">INVOCATIONS</span>
|
||||
</div>
|
||||
<span className="text-foreground-tertiary">/</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-foreground">47ms</span>
|
||||
<span className="text-foreground-secondary">LATENCY</span>
|
||||
<span className="text-foreground">{stats.avgLatency || '--'}ms</span>
|
||||
<span className="text-foreground-secondary">AVG LATENCY</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -71,6 +109,7 @@ export function HeroSection(): React.ReactElement {
|
|||
type="text"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="search tools..."
|
||||
className="brutalist-border h-16 md:h-20 pl-14 pr-36 md:pr-40 text-lg md:text-xl font-mono placeholder:text-foreground-tertiary placeholder:uppercase focus:ring-4 focus:ring-brutalist-accent focus:ring-offset-0 bg-background"
|
||||
style={{ borderRadius: 0 }}
|
||||
|
|
@ -79,6 +118,7 @@ export function HeroSection(): React.ReactElement {
|
|||
{/* Search Button */}
|
||||
<Button
|
||||
size="lg"
|
||||
onClick={handleSearch}
|
||||
className="brutalist-border-thick absolute right-2 top-1/2 -translate-y-1/2 h-12 md:h-16 px-6 md:px-8 bg-brutalist-accent text-foreground hover:bg-brutalist-accent-hover font-bold uppercase tracking-wider shadow-lg"
|
||||
style={{ borderRadius: 0, borderColor: 'hsl(var(--foreground))' }}
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue