diff options
| author | 2023-04-19 17:30:39 +0800 | |
|---|---|---|
| committer | 2023-04-19 17:30:39 +0800 | |
| commit | 3adc965dd09490b7efa1cce9f09b0a3b30970277 (patch) | |
| tree | f813abb07d7b003984aa74e3154752b6ffc3ccd5 /envshare/app/components/stats.tsx | |
| parent | c7c9ca6f0c8eddf6d34cd40779f3b2d9463f3a46 (diff) | |
| download | HydroRoll-3adc965dd09490b7efa1cce9f09b0a3b30970277.tar.gz HydroRoll-3adc965dd09490b7efa1cce9f09b0a3b30970277.zip | |
✨优化文档
Diffstat (limited to 'envshare/app/components/stats.tsx')
| -rw-r--r-- | envshare/app/components/stats.tsx | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/envshare/app/components/stats.tsx b/envshare/app/components/stats.tsx deleted file mode 100644 index be1aa71..0000000 --- a/envshare/app/components/stats.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { Redis } from "@upstash/redis"; - -const redis = Redis.fromEnv(); -export const revalidate = 60; - -export const Stats = asyncComponent(async () => { - const [reads, writes] = await redis - .pipeline() - .get("envshare:metrics:reads") - .get("envshare:metrics:writes") - .exec<[number, number]>(); - const stars = await fetch("https://api.github.com/repos/retrofor/ChienDice") - .then((res) => res.json()) - .then((json) => json.stargazers_count as number); - - const stats = [ - { - label: "Documents Encrypted", - value: writes, - }, - { - label: "Documents Decrypted", - value: reads, - }, - ] satisfies { label: string; value: number }[]; - - if (stars) { - stats.push({ - label: "GitHub Stars", - value: stars, - }); - } - - return ( - <section className="container mx-auto"> - <ul className="grid grid-cols-1 gap-4 sm:grid-cols-3 "> - {stats.map(({ label, value }) => ( - <li - key={label} - className="flex items-center justify-between gap-2 px-4 py-3 overflow-hidden rounded m sm:flex-col" - > - <dd className="text-2xl font-bold tracking-tight text-center sm:text-5xl text-zinc-200"> - {Intl.NumberFormat("en-US", { notation: "compact" }).format(value)} - </dd> - <dt className="leading-6 text-center text-zinc-500">{label}</dt> - </li> - ))} - </ul> - </section> - ); -}); - -// stupid hack to make "server components" actually work with components -// https://www.youtube.com/watch?v=h_9Vx6kio2s -function asyncComponent<T, R>(fn: (arg: T) => Promise<R>): (arg: T) => R { - return fn as (arg: T) => R; -} |
