'use client'
import { ArrowUpRight, Box } from 'lucide-react'
import Link from 'next/link'
import { useRouter, useSearchParams } from 'next/navigation'
import { Suspense, useLayoutEffect, useState } from 'react'
import { Button, cn } from 'ui'
import { CatalogPreview } from '@/components/catalog-preview'
import {
getLibraryBlockHref,
libraryBlocks,
libraryCategories,
type LibraryBlock,
} from '@/config/library'
import { useFrameworkPreference } from '@/context/framework-preference-context'
function LibraryCard({ block, framework }: { block: LibraryBlock; framework: string }) {
return (
{block.title}
{block.category === 'Starter apps' ? 'Starter' : 'Block'}
{block.description}
{block.external && (
View starter on GitHub
)}
)
}
function CategoryFromUrl({ onChange }: { onChange: (category: string | null) => void }) {
const category = useSearchParams().get('category')
useLayoutEffect(() => onChange(category), [category, onChange])
return null
}
export function LibraryOverview() {
const router = useRouter()
const [selectedCategory, setSelectedCategory] = useState(null)
const activeCategory =
libraryCategories.find((category) => category.name === selectedCategory)?.name ?? 'All'
const { framework } = useFrameworkPreference()
const filtered = libraryBlocks.filter(
(block) => activeCategory === 'All' || block.category === activeCategory
)
const sections = libraryCategories
.map((category) => ({
...category,
items: filtered.filter((block) => block.category === category.name),
}))
.filter((section) => section.items.length > 0)
function selectCategory(category: string) {
const params = new URLSearchParams(window.location.search)
if (category === 'All') params.delete('category')
else params.set('category', category)
router.replace(params.size ? `/?${params}` : '/', { scroll: false })
}
return (
Building blocks for your next backend.
Browse blocks
Category
{['All', ...libraryCategories.map((category) => category.name)].map((category) => (
))}
{filtered.length} blocks found
{sections.length > 0 ? (
{sections.map((section) => (
{section.name}
{section.description}
{section.items.map((block) => (
))}
))}
) : (
No blocks found
Try another category.
)}
Components, blocks, and starter apps for Supabase. Add blocks to your project with a
single command.
)
}