File size: 4,078 Bytes
2471af3
 
 
 
 
61db3dc
2471af3
61db3dc
 
2471af3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61db3dc
 
 
 
2471af3
 
 
61db3dc
2471af3
 
 
 
 
 
61db3dc
 
2471af3
61db3dc
2471af3
 
 
61db3dc
2471af3
 
61db3dc
2471af3
61db3dc
 
 
 
 
 
2471af3
61db3dc
 
2471af3
61db3dc
 
2471af3
 
61db3dc
 
2471af3
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { useEffect, useRef, useState } from "react"
import { ArrowLeft, ArrowRight, ArrowUpRight } from "lucide-react"
import type { Release, Site } from "@/lib/types"
import { full, hfUrl, mdy, num } from "@/lib/format"
import { href } from "@/lib/route"
import { Tile } from "@/components/media"

/** Every release in order, as minimax.io shows its flagship models: a card with the model's
 *  picture, its name and date, and the community it has today. */
export function ReleaseRail({ site }: { site: Site }) {
  const rail = useRef<HTMLOListElement>(null)
  const [edge, setEdge] = useState({ start: true, end: false })
  const rels = [...site.releases].sort((a, b) => a.date.localeCompare(b.date))

  const sync = () => {
    const el = rail.current
    if (!el) return
    setEdge({ start: el.scrollLeft < 8, end: el.scrollLeft + el.clientWidth > el.scrollWidth - 8 })
  }
  useEffect(() => {
    const el = rail.current
    if (!el) return
    el.scrollLeft = el.scrollWidth // newest in view; history is a scroll away
    sync()
  }, [])
  const page = (dir: number) => rail.current?.scrollBy({ left: dir * rail.current.clientWidth * 0.8, behavior: "smooth" })

  return (
    <section className="relative mx-auto w-full max-w-[1200px] px-4 sm:px-8">
      <div className="relative mb-8 flex items-center justify-center">
        <h2 className="text-center font-display text-[30px] leading-tight font-semibold tracking-[-0.01em] sm:text-[36px]">Every release</h2>
        <div className="absolute right-0 hidden gap-2 sm:flex">
          {[-1, 1].map((d) => (
            <button key={d} type="button" onClick={() => page(d)} disabled={d < 0 ? edge.start : edge.end}
                    aria-label={d < 0 ? "Earlier releases" : "Later releases"}
                    className="grid size-10 place-items-center rounded-full border border-border bg-white text-foreground transition-colors hover:bg-muted disabled:opacity-35">
              {d < 0 ? <ArrowLeft className="size-4" /> : <ArrowRight className="size-4" />}
            </button>
          ))}
        </div>
      </div>
      <ol ref={rail} onScroll={sync}
          className="-mx-4 flex snap-x snap-mandatory scroll-px-4 gap-4 overflow-x-auto scroll-smooth px-4 pt-1 pb-6 [scrollbar-width:none] sm:-mx-8 sm:scroll-px-8 sm:px-8 [&::-webkit-scrollbar]:hidden">
        {rels.map((r) => <Card key={r.key} r={r} />)}
      </ol>
    </section>
  )
}

function Card({ r }: { r: Release }) {
  const external = !r.page
  return (
    <li className="w-[256px] shrink-0 snap-start sm:w-[272px]">
      <a href={external ? hfUrl(r.base) : href(r.cat, r.key)} target={external ? "_blank" : undefined} rel={external ? "noopener" : undefined}
         className="group flex h-full flex-col rounded-[20px] border border-border bg-white p-2 shadow-[var(--shadow-card)] transition-[transform,box-shadow] duration-300 ease-[cubic-bezier(.22,.61,.36,1)] hover:-translate-y-1 hover:shadow-[0_24px_48px_-20px_rgba(23,23,23,0.28)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring">
        <Tile name={r.name} cat={r.cat} />
        <div className="px-3 pt-4 pb-3">
          <div className="flex items-start justify-between gap-2">
            <span className="font-display text-[19px] leading-snug font-semibold">{r.name.replace(/-/g, " ")}</span>
            {external && <ArrowUpRight className="mt-1 size-4 shrink-0 text-muted-foreground" />}
          </div>
          <div className="mt-1 text-[15px] text-muted-foreground">{mdy(r.date)}</div>
          <div className="mt-5 grid grid-cols-2 gap-3">
            <div>
              <div className="font-serif text-[24px] leading-none">{full(r.n)}</div>
              <div className="mt-2 text-[15px] text-muted-foreground">community</div>
            </div>
            <div>
              <div className="font-serif text-[24px] leading-none">{num(r.official.dlall)}</div>
              <div className="mt-2 text-[15px] text-muted-foreground">downloads</div>
            </div>
          </div>
        </div>
      </a>
    </li>
  )
}