Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions src/components/npm-stats/NPMSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as React from 'react'
import { Suspense } from 'react'
import { useSuspenseQuery } from '@tanstack/react-query'
import { queryOptions } from '@tanstack/react-query'
import { BlankErrorBoundary } from '~/components/BlankErrorBoundary'
import { ossStatsQuery } from '~/queries/stats'
import { ossStatsQuery, recentDownloadsQuery } from '~/queries/stats'
import { useNpmDownloadCounter } from '~/hooks/useNpmDownloadCounter'
import { fetchRecentDownloadStats } from '~/utils/stats-queries.functions'
import type { Library } from '~/libraries'

/**
Expand All @@ -24,26 +22,6 @@ function formatNumber(num: number): string {
return num.toLocaleString()
}

/**
* Query options for recent download stats
*/
function recentDownloadsQuery(library: Library) {
return queryOptions({
queryKey: ['npm-recent-downloads', library.id],
queryFn: () =>
fetchRecentDownloadStats({
data: {
library: {
id: library.id,
repo: library.repo,
frameworks: library.frameworks,
},
},
}),
staleTime: 5 * 60 * 1000, // 5 minutes
})
}

/**
* Animated counter component for all-time downloads
*/
Expand Down Expand Up @@ -110,7 +88,9 @@ function NPMSummaryContent({ library }: { library: Library }) {
const { data: ossStats } = useSuspenseQuery(ossStatsQuery({ library }))

// Fetch recent download stats (daily, weekly, monthly)
const { data: recentStats } = useSuspenseQuery(recentDownloadsQuery(library))
const { data: recentStats } = useSuspenseQuery(
recentDownloadsQuery({ library }),
)

return (
<div className="my-6">
Expand Down
Loading