@@ -60,8 +60,10 @@ type LoaderData = {
6060 totalMonthDownloads : number ;
6161 yesterdayDownloads ?: { day : string ; downloads : number } ;
6262 peakYearlyDayDownloads ?: { day : string ; downloads : number } ;
63+ last31DaysDownloads : CranDownloadsResponse ;
6364 monthlyDayDownloadsComment : string ;
6465 totalYearDownloads : number ;
66+ totalLast31DaysDownloads : number ;
6567 totalYearlyDownloadsComment : string ;
6668 indexOfTrendingItems : number ;
6769 indexOfTopDownloads : number ;
@@ -165,12 +167,14 @@ export const loader: LoaderFunction = async ({ params }) => {
165167 maintainer : undefined ,
166168 dailyDownloads : [ ] ,
167169 yearlyDailyDownloads : [ ] ,
170+ last31DaysDownloads : [ ] ,
168171 lastRelease : "" ,
169172 totalMonthDownloads : 0 ,
170173 yesterdayDownloads : undefined ,
171174 peakYearlyDayDownloads : undefined ,
172175 monthlyDayDownloadsComment : "" ,
173176 totalYearDownloads : 0 ,
177+ totalLast31DaysDownloads : 0 ,
174178 totalYearlyDownloadsComment : "" ,
175179 indexOfTrendingItems : - 1 ,
176180 indexOfTopDownloads : - 1 ,
@@ -285,6 +289,21 @@ export const loader: LoaderFunction = async ({ params }) => {
285289 loaderData . indexOfTopDownloads = _topDownloads ?. downloads . findIndex (
286290 ( item ) => item . package === packageName ,
287291 ) ;
292+
293+ if ( loaderData . yearlyDailyDownloads . at ( 0 ) ) {
294+ const yearly = loaderData . yearlyDailyDownloads . at ( 0 ) ! ;
295+ loaderData . last31DaysDownloads = [
296+ {
297+ ...yearly ,
298+ downloads : yearly . downloads . slice ( - 31 ) ,
299+ } ,
300+ ] ;
301+ loaderData . totalLast31DaysDownloads =
302+ loaderData . last31DaysDownloads [ 0 ] . downloads . reduce (
303+ ( acc , curr ) => acc + curr . downloads ,
304+ 0 ,
305+ ) ;
306+ }
288307 } catch ( error ) {
289308 slog . error ( error ) ;
290309 throw new Response ( null , {
@@ -310,11 +329,13 @@ export default function PackagePage() {
310329 authors,
311330 dailyDownloads,
312331 yearlyDailyDownloads,
332+ last31DaysDownloads,
313333 lastRelease,
314334 totalMonthDownloads,
315335 yesterdayDownloads,
316336 totalYearDownloads,
317337 totalYearlyDownloadsComment,
338+ totalLast31DaysDownloads,
318339 monthlyDayDownloadsComment,
319340 peakYearlyDayDownloads,
320341 indexOfTrendingItems,
@@ -367,6 +388,8 @@ export default function PackagePage() {
367388 totalYearDownloads = { totalYearDownloads }
368389 monthlyDayDownloadsComment = { monthlyDayDownloadsComment }
369390 totalYearlyDownloadsComment = { totalYearlyDownloadsComment }
391+ last31DaysDownloads = { last31DaysDownloads }
392+ totalLast31DaysDownloads = { totalLast31DaysDownloads }
370393 />
371394
372395 < BinariesPageContentSection
@@ -709,6 +732,8 @@ function InsightsPageContentSection(
709732 | "monthlyDayDownloadsComment"
710733 | "totalYearlyDownloadsComment"
711734 | "totalYearDownloads"
735+ | "last31DaysDownloads"
736+ | "totalLast31DaysDownloads"
712737 > ,
713738) {
714739 const {
@@ -720,6 +745,7 @@ function InsightsPageContentSection(
720745 totalYearDownloads,
721746 monthlyDayDownloadsComment,
722747 totalYearlyDownloadsComment,
748+ last31DaysDownloads,
723749 } = props ;
724750
725751 const nrFormatter = new Intl . NumberFormat ( "en-US" ) ;
@@ -791,6 +817,29 @@ function InsightsPageContentSection(
791817 />
792818 ) }
793819 </ ClientOnly >
820+
821+ < div className = "space-y-4" >
822+ < p >
823+ The following line graph shows the downloads per day. You can
824+ hover over the graph to see the exact number of downloads per
825+ day.
826+ </ p >
827+ </ div >
828+ < ClientOnly
829+ fallback = {
830+ < div className = "h-200 bg-gray-ui animate-pulse rounded-md" />
831+ }
832+ >
833+ { ( ) => (
834+ < LineGraph
835+ height = { 200 }
836+ data = { last31DaysDownloads [ 0 ] . downloads . map ( ( d ) => ( {
837+ date : d . day ,
838+ value : d . downloads ,
839+ } ) ) }
840+ />
841+ ) }
842+ </ ClientOnly >
794843 </ >
795844 ) : null }
796845
0 commit comments