f94714bbdf
Imports the public marketing site previously living in ../oh-my-opencode-web. Independent of the npm plugin: own package.json, bun.lock, tsconfig.json. Not included in the published package — root files: array still only ships dist/, bin/, postinstall.mjs. Stack: - Next.js 15.5 App Router + RSC, deployed to Cloudflare Workers via @opennextjs/cloudflare (build target .open-next/worker.js). - Tailwind v4 + shadcn/ui primitives. - next-intl with 4 locales (en/ja/ko/zh) under app/[locale]/. - Playwright e2e tests under web/e2e/. - Custom domains ohmyopenagent.com (primary) and ohmyopencode.org (legacy alias) declared in web/wrangler.toml. Source files were re-formatted via `bun run format` to bring them in line with the existing .prettierrc (singleQuote: false). Functional code unchanged.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect, useState } from "react"
|
|
|
|
interface StatsData {
|
|
stars: string
|
|
totalDownloads: string
|
|
monthlyDownloads: string
|
|
weeklyDownloads: string
|
|
}
|
|
|
|
export function useLiveStats(initial: StatsData): StatsData {
|
|
const [stats, setStats] = useState<StatsData>(initial)
|
|
|
|
useEffect(() => {
|
|
let cancelled = false
|
|
async function refresh() {
|
|
try {
|
|
const res = await fetch("/api/stats")
|
|
if (!res.ok || cancelled) return
|
|
const data = await res.json()
|
|
if (cancelled) return
|
|
setStats({
|
|
stars: data.stars ?? initial.stars,
|
|
totalDownloads: data.totalDownloads ?? initial.totalDownloads,
|
|
monthlyDownloads: data.monthlyDownloads ?? initial.monthlyDownloads,
|
|
weeklyDownloads: data.weeklyDownloads ?? initial.weeklyDownloads,
|
|
})
|
|
} catch {
|
|
// keep SSG values on error
|
|
}
|
|
}
|
|
refresh()
|
|
return () => {
|
|
cancelled = true
|
|
}
|
|
}, [initial.stars, initial.totalDownloads, initial.monthlyDownloads, initial.weeklyDownloads])
|
|
|
|
return stats
|
|
}
|