|
1 | 1 | import { Download } from 'lucide-react'
|
2 |
| -import { twMerge } from 'tailwind-merge' |
3 |
| -import { fetchNpmPackage } from '../lib/npm' |
4 |
| -import { SvgCurveGraph } from './svg-curve-graph' |
| 2 | +import { Suspense } from 'react' |
| 3 | +import { formatStatNumber } from '../lib/format' |
| 4 | +import { combineStats, fetchNpmPackage } from '../lib/npm' |
| 5 | +import { DownloadsGraph } from './downloads.client' |
| 6 | +import { BarList } from './tremor' |
5 | 7 |
|
6 |
| -type DownloadsGraphProps = React.ComponentProps<'section'> & {} |
7 |
| - |
8 |
| -const formatter = new Intl.NumberFormat('en-GB', { |
9 |
| - compactDisplay: 'short', |
10 |
| - notation: 'compact' |
11 |
| -}) |
| 8 | +export async function NPMStats() { |
| 9 | + const [nuqs, nextUseQueryState] = await Promise.all([ |
| 10 | + fetchNpmPackage('nuqs'), |
| 11 | + fetchNpmPackage('next-usequerystate') |
| 12 | + ]) |
| 13 | + const both = combineStats(nuqs, nextUseQueryState) |
| 14 | + return ( |
| 15 | + <> |
| 16 | + <h3 className="flex items-center gap-2 text-4xl font-bold"> |
| 17 | + <Download size={32} /> {formatStatNumber(both.allTime)} |
| 18 | + </h3> |
| 19 | + <BarList |
| 20 | + data={[ |
| 21 | + { |
| 22 | + name: 'next-usequerystate', |
| 23 | + value: nextUseQueryState.allTime, |
| 24 | + color: 'zinc' |
| 25 | + }, |
| 26 | + { name: 'nuqs', value: nuqs.allTime, color: 'red' } |
| 27 | + ]} |
| 28 | + className="flex-1" |
| 29 | + /> |
| 30 | + </> |
| 31 | + ) |
| 32 | +} |
12 | 33 |
|
13 |
| -export async function DownloadsGraph({ |
14 |
| - className, |
15 |
| - ...props |
16 |
| -}: DownloadsGraphProps) { |
| 34 | +export async function NPMDownloads() { |
17 | 35 | const [nuqs, nextUseQueryState] = await Promise.all([
|
18 | 36 | fetchNpmPackage('nuqs'),
|
19 | 37 | fetchNpmPackage('next-usequerystate')
|
20 | 38 | ])
|
21 |
| - const last30Days = nuqs.last30Days.reduce((acc, x, i) => { |
22 |
| - acc[i] = x + nextUseQueryState.last30Days[i] |
23 |
| - return acc |
24 |
| - }, [] as number[]) |
25 |
| - const totalDownloads = nuqs.allTime + nextUseQueryState.allTime |
| 39 | + const both = combineStats(nuqs, nextUseQueryState) |
26 | 40 | return (
|
27 |
| - <section className={twMerge('relative', className)} {...props}> |
28 |
| - <SvgCurveGraph |
29 |
| - data={last30Days} |
30 |
| - lastDate={nuqs.lastDate} |
31 |
| - height={200} |
32 |
| - summaryValue={last30Days.reduce((sum, x) => sum + x)} |
33 |
| - className="text-red-500" |
| 41 | + <Suspense> |
| 42 | + <DownloadsGraph |
| 43 | + data={both.last90Days} |
| 44 | + dataKeys={['nuqs', 'next-usequerystate']} |
| 45 | + title={ |
| 46 | + <> |
| 47 | + <Download size={20} /> Last 90 days |
| 48 | + </> |
| 49 | + } |
34 | 50 | />
|
35 |
| - <p className="absolute left-2 top-2 flex items-center gap-2 text-2xl font-semibold tabular-nums md:text-6xl"> |
36 |
| - <Download |
37 |
| - aria-label="NPM package downloads" |
38 |
| - className="inline-block md:h-12 md:w-12" |
39 |
| - />{' '} |
40 |
| - {formatter.format(totalDownloads)} |
41 |
| - </p> |
42 |
| - </section> |
| 51 | + <DownloadsGraph |
| 52 | + data={both.last30Days} |
| 53 | + dataKeys={['nuqs', 'next-usequerystate']} |
| 54 | + title={ |
| 55 | + <> |
| 56 | + <Download size={20} /> Last 30 days |
| 57 | + </> |
| 58 | + } |
| 59 | + /> |
| 60 | + </Suspense> |
| 61 | + // <section className={twMerge('relative', className)} {...props}> |
| 62 | + // <LineChart |
| 63 | + // data= |
| 64 | + |
| 65 | + // /> |
| 66 | + |
| 67 | + // <SvgCurveGraph |
| 68 | + // data={last30Days} |
| 69 | + // lastDate={nuqs.lastDate} |
| 70 | + // height={200} |
| 71 | + // summaryValue={last30Days.reduce((sum, x) => sum + x)} |
| 72 | + // className="text-red-500" |
| 73 | + // /> |
| 74 | + // <p className="absolute left-2 top-2 flex items-center gap-2 text-2xl font-semibold tabular-nums md:text-6xl"> |
| 75 | + // <Download |
| 76 | + // aria-label="NPM package downloads" |
| 77 | + // className="inline-block md:h-12 md:w-12" |
| 78 | + // />{' '} |
| 79 | + // {formatter.format(totalDownloads)} |
| 80 | + // </p> |
| 81 | + // </section> |
43 | 82 | )
|
44 | 83 | }
|
0 commit comments