Toplist ((full)) -
if (loading) return <div>Loading toplist...</div>;
<ol className="space-y-2"> items.map((item, index) => ( <li key=item.id className="flex items-center gap-4 p-2 hover:bg-gray-50 rounded"> <span className="font-bold text-lg w-8 text-center"> index === 0 ? '🥇' : index === 1 ? '🥈' : index === 2 ? '🥉' : `#$index + 1` </span> <img src=item.thumbnail alt=item.name className="w-12 h-12 object-cover rounded" /> <div className="flex-1"> <div className="font-semibold">item.name</div> <div className="text-sm text-gray-500">item.category</div> </div> <div className="text-right"> <div className="font-bold text-lg">item.score</div> <div className="text-xs text-gray-400">item.metricLabel</div> </div> </li> )) </ol> </div> ); ; toplist
const timeCondition = interval ? AND i.created_at > NOW() - INTERVAL '$interval' : ''; if (loading) return <div>Loading toplist
A toplist displays ranked items based on a specific metric (e.g., most popular, highest rated, most viewed). 1. Frontend Component (React + Tailwind) import useState, useEffect from 'react'; const Toplist = ( endpoint, limit = 10, title ) => const [items, setItems] = useState([]); const [loading, setLoading] = useState(true); const [timeframe, setTimeframe] = useState('week'); '🥉' : `#$index + 1` </span> <img src=item
const query = SELECT items.id, items.name, items.category, items.thumbnail, COUNT(interactions.id) as score, '$metric' as metric_label FROM items LEFT JOIN interactions ON items.id = interactions.item_id AND interactions.type = $1 $timeCondition GROUP BY items.id ORDER BY score DESC LIMIT $2 ;