import { Link } from "@tanstack/react-router"; import { useEffect, useState } from "react"; import { counts, cover, filtered, sorted, split, SUBMIT, type App, type Catalog, type Sort } from "../apps"; import data from "../showcase.json"; export const catalog = data as Catalog; /** The day an app joined, as its manifest wrote it. */ export const joined = (app: App) => new Date(`${app.publishedAt.slice(0, 10)}T00:00:00Z`).toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric", timeZone: "UTC" }); export const starCount = (n: number) => `${new Intl.NumberFormat("en-US", { notation: "compact" }).format(n)} ${n === 1 ? "star" : "stars"}`; function Card({ app }: { app: App }) { return (
  • {app.name} {app.building && Building} {app.author} {app.description} {app.platforms.join(" · ")} {app.stars !== undefined && {starCount(app.stars)}} {joined(app)}
  • ); } function Grid({ apps, label }: { apps: App[]; label: string }) { return ( ); } export function Submit() { return (

    Built something with Ely?

    Add it by pull request to the showcase repository.

    Submit your app
    ); } export function Showcase() { const [query, setQuery] = useState(""); const [category, setCategory] = useState(null); const [sort, setSort] = useState("newest"); useEffect(() => { document.title = "Showcase · Ely"; }, []); const { featured, rest } = split(catalog); const searching = query.trim() !== "" || category !== null; const found = sorted(filtered(catalog.apps, query, category), sort); const empty = catalog.apps.length === 0; return ( <>

    Showcase.

    Apps built with Ely.

    {empty ? (

    No apps yet. Yours could be the first.

    ) : ( <> setQuery(e.target.value)} onKeyDown={(e) => e.key === "Escape" && setQuery("")} />
    {counts(catalog).map(([key, label, n]) => ( ))}
    {searching ? ( found.length ? :

    Nothing matches.

    ) : ( <> {featured.length > 0 && ( <>

    Featured

    )} {rest.length > 0 && ( <>

    {featured.length ? "More apps" : "All apps"}

    )} )} )}
    ); }