From 409b2d3b10ca27c7ef5c8983b67059d9aa80d1d7 Mon Sep 17 00:00:00 2001 From: anandmindfire Date: Fri, 10 May 2024 15:02:05 +0530 Subject: [PATCH 1/3] feat: add loader in download count --- src/app/packages/page.tsx | 46 +++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/app/packages/page.tsx b/src/app/packages/page.tsx index 2e3ffd23..3cddf9b4 100644 --- a/src/app/packages/page.tsx +++ b/src/app/packages/page.tsx @@ -23,7 +23,7 @@ type download = { const Stats = () => { const [startDate, setStartDate] = useState(moment().format("YYYY-MM-DD")); const [endDate, setEndDate] = useState(moment().format("YYYY-MM-DD")); - + const [loading, setLoading] = useState(false); // State to track loading status const [count, setCount] = useState(0); const [selectedRange, setSelectedRange] = useState(false); const [isOpen, setIsOpen] = useState(false); @@ -50,6 +50,7 @@ const Stats = () => { // Function to fetch download statistics for a given package and period async function fetchDownloadStats(packageName: string, period: string) { + setLoading(true); const url = `https://api.npmjs.org/downloads/range/${period}/@mindfiredigital/${packageName}`; const response = await fetch(url); @@ -57,9 +58,11 @@ const Stats = () => { console.log( `Failed to fetch download stats for ${packageName} (${period}): ${response.statusText}` ); + setLoading(false); } const data = await response.json(); + setLoading(false); return data; } @@ -103,13 +106,16 @@ const Stats = () => { const range: { start: string; end: string } = getDateRange( event.target.value as string ); + getStats(_package.name, `${range?.start}:${range?.end}`).then((res) => { + setLoading(true); const count = calculateDownloads(res); // console.log(count); packages.map((npmPackage) => { if (npmPackage.name === _package.name) { setCount(count); + setLoading(false); } return npmPackage; }); @@ -468,9 +474,22 @@ const Stats = () => { quality={75} />
-
- {count} -
+ {loading ? ( + // Render loading indicator while count is being fetched +
+ + {" "} + +
+ ) : ( + // Render count when it is available +
+ {count} +
+ )}
@@ -496,9 +515,22 @@ const Stats = () => { quality={75} />
-
- {count} -
+ {loading ? ( + // Render loading indicator while count is being fetched +
+ + {" "} + +
+ ) : ( + // Render count when it is available +
+ {count} +
+ )}
From 72223aef496ca781f1efb9022d6fd9c2dc66a85b Mon Sep 17 00:00:00 2001 From: anandmindfire Date: Fri, 10 May 2024 15:03:36 +0530 Subject: [PATCH 2/3] feat: add sub header in packages page --- src/app/packages/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/packages/page.tsx b/src/app/packages/page.tsx index 3cddf9b4..d82ba5fd 100644 --- a/src/app/packages/page.tsx +++ b/src/app/packages/page.tsx @@ -230,8 +230,8 @@ const Stats = () => { Download Statistics

- We are a dynamic group of individuals who are passionate about what we - do. + Elevate your projects with Mindfire's game-changing open-source + packages.

{packages.map((package_list) => ( From d7032538d760f43f1356693c16fc6f1d44ee2828 Mon Sep 17 00:00:00 2001 From: anandmindfire Date: Fri, 10 May 2024 15:06:33 +0530 Subject: [PATCH 3/3] fix: fix header in packages page --- src/app/packages/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/packages/page.tsx b/src/app/packages/page.tsx index d82ba5fd..6bf89a0f 100644 --- a/src/app/packages/page.tsx +++ b/src/app/packages/page.tsx @@ -227,7 +227,7 @@ const Stats = () => {

- Download Statistics + Our Packages

Elevate your projects with Mindfire's game-changing open-source