Skip to content

Commit 08c1019

Browse files
ci: apply automated fixes
1 parent ad70ff5 commit 08c1019

File tree

3 files changed

+113
-85
lines changed

3 files changed

+113
-85
lines changed

src/components/NpmStatsComponent.tsx

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,11 @@ interface NpmStatsComponentProps {
825825
competitors?: string[]
826826
frameworks?: string[]
827827
libraryId?: string
828-
getPackageName?: (framework: string, libraryId: string, library: any) => string
828+
getPackageName?: (
829+
framework: string,
830+
libraryId: string,
831+
library: any,
832+
) => string
829833
library?: any
830834
}
831835

@@ -1789,49 +1793,57 @@ export function NpmStatsComponent({
17891793
) : null}
17901794

17911795
{/* Framework Adapters Section */}
1792-
{frameworks && frameworks.length > 0 && libraryId && getPackageName && library && (
1793-
<div className="mb-6">
1794-
<h2 className="text-lg font-semibold mb-3">
1795-
Add Framework Adapters
1796-
</h2>
1797-
<div className="flex flex-wrap gap-2">
1798-
{frameworks.map((framework) => {
1799-
const frameworkPackageName = getPackageName(framework, libraryId, library)
1800-
const isAlreadyAdded = packageGroups.some((pg) =>
1801-
pg.packages.some((pkg) => pkg.name === frameworkPackageName),
1802-
)
1803-
1804-
return (
1805-
<button
1806-
key={framework}
1807-
onClick={() => {
1808-
if (!isAlreadyAdded) {
1809-
const newPackageGroups = [
1810-
...packageGroups,
1811-
{
1812-
packages: [{ name: frameworkPackageName }],
1813-
// Don't set color - let default color assignment work
1814-
},
1815-
]
1816-
onPackageGroupsChange(newPackageGroups)
1817-
}
1818-
}}
1819-
disabled={isAlreadyAdded}
1820-
className={twMerge(
1821-
'px-3 py-1.5 rounded-md text-sm font-medium transition-colors capitalize',
1822-
isAlreadyAdded
1823-
? 'bg-gray-200 text-gray-500 dark:bg-gray-700 dark:text-gray-400 cursor-not-allowed'
1824-
: 'bg-emerald-500/10 hover:bg-emerald-500/20 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20 hover:border-emerald-500/30',
1825-
)}
1826-
>
1827-
{isAlreadyAdded ? '✓ ' : '+ '}
1828-
{framework === 'vanilla' ? 'Vanilla (Core)' : framework}
1829-
</button>
1830-
)
1831-
})}
1796+
{frameworks &&
1797+
frameworks.length > 0 &&
1798+
libraryId &&
1799+
getPackageName &&
1800+
library && (
1801+
<div className="mb-6">
1802+
<h2 className="text-lg font-semibold mb-3">
1803+
Add Framework Adapters
1804+
</h2>
1805+
<div className="flex flex-wrap gap-2">
1806+
{frameworks.map((framework) => {
1807+
const frameworkPackageName = getPackageName(
1808+
framework,
1809+
libraryId,
1810+
library,
1811+
)
1812+
const isAlreadyAdded = packageGroups.some((pg) =>
1813+
pg.packages.some((pkg) => pkg.name === frameworkPackageName),
1814+
)
1815+
1816+
return (
1817+
<button
1818+
key={framework}
1819+
onClick={() => {
1820+
if (!isAlreadyAdded) {
1821+
const newPackageGroups = [
1822+
...packageGroups,
1823+
{
1824+
packages: [{ name: frameworkPackageName }],
1825+
// Don't set color - let default color assignment work
1826+
},
1827+
]
1828+
onPackageGroupsChange(newPackageGroups)
1829+
}
1830+
}}
1831+
disabled={isAlreadyAdded}
1832+
className={twMerge(
1833+
'px-3 py-1.5 rounded-md text-sm font-medium transition-colors capitalize',
1834+
isAlreadyAdded
1835+
? 'bg-gray-200 text-gray-500 dark:bg-gray-700 dark:text-gray-400 cursor-not-allowed'
1836+
: 'bg-emerald-500/10 hover:bg-emerald-500/20 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20 hover:border-emerald-500/30',
1837+
)}
1838+
>
1839+
{isAlreadyAdded ? '✓ ' : '+ '}
1840+
{framework === 'vanilla' ? 'Vanilla (Core)' : framework}
1841+
</button>
1842+
)
1843+
})}
1844+
</div>
18321845
</div>
1833-
</div>
1834-
)}
1846+
)}
18351847

18361848
{/* Competitor Packages Section */}
18371849
{competitors && competitors.length > 0 && (

src/components/NpmStatsSummaryBar.tsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ function isValidMetric(value: number | undefined | null): boolean {
8383
)
8484
}
8585

86-
function NpmStatsSummaryContent({
87-
library
88-
}: {
89-
library: Library
90-
}) {
86+
function NpmStatsSummaryContent({ library }: { library: Library }) {
9187
const { data: stats } = useSuspenseQuery(ossStatsQuery({ library }))
92-
const { data: recentStats } = useSuspenseQuery(recentDownloadStatsQuery({ library }))
88+
const { data: recentStats } = useSuspenseQuery(
89+
recentDownloadStatsQuery({ library }),
90+
)
9391

9492
const npmDownloads = stats.npm?.totalDownloads ?? 0
9593
const hasNpmDownloads = isValidMetric(npmDownloads)
@@ -150,29 +148,29 @@ function NpmStatsSummaryContent({
150148
)
151149
}
152150

153-
export default function NpmStatsSummaryBar({
154-
library
155-
}: {
156-
library: Library
157-
}) {
151+
export default function NpmStatsSummaryBar({ library }: { library: Library }) {
158152
return (
159-
<Suspense fallback={
160-
<div className="mb-6">
161-
<div className="animate-pulse">
162-
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
163-
{Array(4).fill(0).map((_, i) => (
164-
<div key={i} className="text-left">
165-
<div className="h-9 bg-gray-300 dark:bg-gray-700 rounded w-20 mb-2"></div>
166-
<div className="h-4 bg-gray-300 dark:bg-gray-700 rounded w-16"></div>
167-
</div>
168-
))}
153+
<Suspense
154+
fallback={
155+
<div className="mb-6">
156+
<div className="animate-pulse">
157+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
158+
{Array(4)
159+
.fill(0)
160+
.map((_, i) => (
161+
<div key={i} className="text-left">
162+
<div className="h-9 bg-gray-300 dark:bg-gray-700 rounded w-20 mb-2"></div>
163+
<div className="h-4 bg-gray-300 dark:bg-gray-700 rounded w-16"></div>
164+
</div>
165+
))}
166+
</div>
169167
</div>
170168
</div>
171-
</div>
172-
}>
169+
}
170+
>
173171
<BlankErrorBoundary>
174172
<NpmStatsSummaryContent library={library} />
175173
</BlankErrorBoundary>
176174
</Suspense>
177175
)
178-
}
176+
}

src/utils/stats.server.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,11 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
609609
})
610610

611611
// Import db functions dynamically
612-
const { getRegisteredPackages, getBatchNpmDownloadChunks, setCachedNpmDownloadChunk } =
613-
await import('./stats-db.server')
612+
const {
613+
getRegisteredPackages,
614+
getBatchNpmDownloadChunks,
615+
setCachedNpmDownloadChunk,
616+
} = await import('./stats-db.server')
614617

615618
// Get registered packages for this library (same as getOSSStats)
616619
let npmPackageNames = await getRegisteredPackages(data.library.id)
@@ -622,11 +625,17 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
622625

623626
const today = new Date()
624627
const todayStr = today.toISOString().substring(0, 10)
625-
628+
626629
// Calculate date ranges
627-
const dailyStart = new Date(today.getTime() - 24 * 60 * 60 * 1000).toISOString().substring(0, 10)
628-
const weeklyStart = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000).toISOString().substring(0, 10)
629-
const monthlyStart = new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000).toISOString().substring(0, 10)
630+
const dailyStart = new Date(today.getTime() - 24 * 60 * 60 * 1000)
631+
.toISOString()
632+
.substring(0, 10)
633+
const weeklyStart = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000)
634+
.toISOString()
635+
.substring(0, 10)
636+
const monthlyStart = new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000)
637+
.toISOString()
638+
.substring(0, 10)
630639

631640
// Create chunk requests for all packages and time periods
632641
const chunkRequests = []
@@ -637,23 +646,23 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
637646
dateFrom: dailyStart,
638647
dateTo: todayStr,
639648
binSize: 'daily',
640-
period: 'daily'
649+
period: 'daily',
641650
})
642651
// Weekly data (last 7 days)
643652
chunkRequests.push({
644653
packageName,
645654
dateFrom: weeklyStart,
646655
dateTo: todayStr,
647656
binSize: 'daily',
648-
period: 'weekly'
657+
period: 'weekly',
649658
})
650659
// Monthly data (last 30 days)
651660
chunkRequests.push({
652661
packageName,
653662
dateFrom: monthlyStart,
654663
dateTo: todayStr,
655664
binSize: 'daily',
656-
period: 'monthly'
665+
period: 'monthly',
657666
})
658667
}
659668

@@ -666,18 +675,18 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
666675
for (const req of chunkRequests) {
667676
const cacheKey = `${req.packageName}|${req.dateFrom}|${req.dateTo}|${req.binSize}`
668677
const cached = cachedChunks.get(cacheKey)
669-
678+
670679
if (cached) {
671680
// Check if cache is recent enough (within last hour for recent data)
672681
const cacheAge = Date.now() - (cached.updatedAt ?? 0)
673682
const isStale = cacheAge > 60 * 60 * 1000 // 1 hour
674-
683+
675684
if (!isStale) {
676685
results.set(cacheKey, cached)
677686
continue
678687
}
679688
}
680-
689+
681690
needsFetch.push(req)
682691
}
683692

@@ -709,7 +718,7 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
709718
totalDownloads: 0,
710719
isImmutable: false,
711720
updatedAt: Date.now(),
712-
}
721+
},
713722
}
714723
}
715724
throw new Error(`NPM API error: ${response.status}`)
@@ -723,23 +732,32 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
723732
dateFrom: req.dateFrom,
724733
dateTo: req.dateTo,
725734
binSize: req.binSize,
726-
totalDownloads: downloads.reduce((sum: number, d: any) => sum + d.downloads, 0),
735+
totalDownloads: downloads.reduce(
736+
(sum: number, d: any) => sum + d.downloads,
737+
0,
738+
),
727739
dailyData: downloads,
728740
isImmutable: false, // Recent data is mutable
729741
updatedAt: Date.now(),
730742
}
731743

732744
// Cache this chunk asynchronously
733745
setCachedNpmDownloadChunk(chunkData).catch((err) =>
734-
console.warn(`Failed to cache recent downloads for ${req.packageName}:`, err)
746+
console.warn(
747+
`Failed to cache recent downloads for ${req.packageName}:`,
748+
err,
749+
),
735750
)
736751

737752
return {
738753
key: `${req.packageName}|${req.dateFrom}|${req.dateTo}|${req.binSize}`,
739754
data: chunkData,
740755
}
741756
} catch (error) {
742-
console.error(`Failed to fetch recent downloads for ${req.packageName}:`, error)
757+
console.error(
758+
`Failed to fetch recent downloads for ${req.packageName}:`,
759+
error,
760+
)
743761
// Return zero data on error
744762
return {
745763
key: `${req.packageName}|${req.dateFrom}|${req.dateTo}|${req.binSize}`,
@@ -771,10 +789,10 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
771789
for (const req of chunkRequests) {
772790
const cacheKey = `${req.packageName}|${req.dateFrom}|${req.dateTo}|${req.binSize}`
773791
const chunk = results.get(cacheKey)
774-
792+
775793
if (chunk) {
776794
const downloads = chunk.totalDownloads || 0
777-
795+
778796
if (req.period === 'daily') {
779797
dailyTotal += downloads
780798
} else if (req.period === 'weekly') {

0 commit comments

Comments
 (0)