chore(web): improve npm version logic

This commit is contained in:
Aman Varshney
2025-08-05 14:47:47 +05:30
parent b06fa745b0
commit 4ae27bbac6

View File

@@ -1,15 +1,12 @@
"use client";
import { useEffect, useState } from "react";
import { cn } from "@/lib/utils";
const NpmPackage = () => {
const [version, setVersion] = useState("");
const [versionLoading, setVersionLoading] = useState(true);
const [version, setVersion] = useState("0.0.0");
useEffect(() => {
const getLatestVersion = async () => {
setVersionLoading(true);
try {
const res = await fetch(
"https://api.github.com/repos/AmanVarshney01/create-better-t-stack/releases",
@@ -21,8 +18,6 @@ const NpmPackage = () => {
} catch (error) {
console.error("Error fetching NPM version:", error);
setVersion("?.?.?");
} finally {
setVersionLoading(false);
}
};
getLatestVersion();
@@ -30,15 +25,8 @@ const NpmPackage = () => {
return (
<div className="mt-2 flex items-center justify-center">
<span
className={cn(
"mr-2 inline-block h-5 w-3 bg-primary",
versionLoading && "animate-pulse",
)}
/>
<span className=" text-muted-foreground text-xl">
{versionLoading ? "[v?.?.?]" : `[v${version}]`}
</span>
<span className="mr-2 inline-block h-5 w-3 bg-primary" />
<span className="text-muted-foreground text-xl">[v{version}]</span>
</div>
);
};