Files
Pien-Studio/apps/web/components/footer.tsx
T

33 lines
860 B
TypeScript
Raw Normal View History

2026-05-16 11:51:11 +07:00
"use client";
import { useEffect, useState } from "react";
2026-05-16 12:08:27 +07:00
const BUILD_HASH = process.env.NEXT_PUBLIC_GIT_HASH || "unknown";
2026-05-31 03:03:49 +07:00
const SHOULD_LOAD_DEV_HASH =
process.env.NODE_ENV === "development" && BUILD_HASH === "unknown";
2026-05-16 12:08:27 +07:00
function formatHash(hash: string) {
return hash === "unknown" ? hash : hash.slice(0, 7);
}
2026-05-16 11:51:11 +07:00
export function Footer() {
2026-05-16 12:08:27 +07:00
const [hash, setHash] = useState(formatHash(BUILD_HASH));
2026-05-16 11:51:11 +07:00
useEffect(() => {
2026-05-16 12:08:27 +07:00
if (!SHOULD_LOAD_DEV_HASH) return;
2026-05-16 11:51:11 +07:00
fetch("/api/commit-hash")
.then((res) => res.json())
2026-05-31 03:03:49 +07:00
.then((data: { hash?: string }) =>
setHash(formatHash(data.hash || "unknown")),
)
2026-05-16 11:51:11 +07:00
.catch(() => setHash("unknown"));
}, []);
return (
<footer className="fixed bottom-2 right-4 py-1 pointer-events-none">
<span className="text-xs text-gray-400 font-mono">{hash}</span>
</footer>
);
2026-05-16 12:08:27 +07:00
}