import { Accordion, Alert, Badge, Spinner, Table } from "react-bootstrap";
import { useParams } from "react-router";
import { usePackages } from "../hooks/usePackages.ts";
import { CodeBlock } from "../components/CodeBlock.tsx";
function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
export function PackageDetail() {
const { name } = useParams<{ name: string }>();
const { packages, loading, error } = usePackages();
if (loading) return ;
if (error) return Failed to load packages: {error};
if (packages.length === 0) return No package data available.;
const versions = packages
.filter((p) => p.name === name)
.sort((a, b) => b.buildTime - a.buildTime);
if (versions.length === 0)
return Package not found: {name};
const latest = versions[0];
const hasUnstable = versions.some((v) => v.channel === "unstable");
return (
<>
{name}
{latest.summary}
{`sudo dnf install ${name}`}
{hasUnstable && (
{`# install latest unstable version\nsudo dnf --enablerepo=lair-cafe-unstable install ${name}`}
)}
Versions {versions.length}
| Version |
Channel |
Size |
Built |
Download |
{versions.map((pkg) => (
|
{pkg.version}-{pkg.release}
|
{pkg.channel}
|
{formatBytes(pkg.size)} |
{new Date(pkg.buildTime * 1000).toLocaleDateString()} |
{pkg.rpmFilename}
|
))}
{versions.some((v) => v.changelog.length > 0) && (
<>
Changelog
{versions
.filter((v) => v.changelog.length > 0)
.map((pkg) => (
{pkg.version}-{pkg.release} —{" "}
{new Date(pkg.buildTime * 1000).toLocaleDateString()}
{pkg.changelog.map((entry, i) => (
{new Date(entry.date * 1000).toLocaleDateString()}{" "}
— {entry.author}
{entry.text}
))}
))}
>
)}
>
);
}