diff --git a/src/app/packages/page.tsx b/src/app/packages/page.tsx index 2e3ffd23..6bf89a0f 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; }); @@ -221,11 +227,11 @@ const Stats = () => {

- Download Statistics + Our Packages

- 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) => ( @@ -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} +
+ )}