Files
web2app/web/src/pages/JobStatus.tsx

125 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useState } from "react";
import { Link, useParams } from "react-router-dom";
import { fetchBuild, statusLabel, type Build } from "../api";
export default function JobStatus() {
const { id } = useParams<{ id: string }>();
const [build, setBuild] = useState<Build | null>(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!id) return;
let cancelled = false;
async function poll() {
try {
const data = await fetchBuild(id!);
if (cancelled) return;
setBuild(data);
setError(null);
if (data.status === "completed" || data.status === "failed") {
return;
}
window.setTimeout(poll, 5000);
} catch (err) {
if (cancelled) return;
setError(err instanceof Error ? err.message : "加载失败");
window.setTimeout(poll, 5000);
}
}
poll();
return () => {
cancelled = true;
};
}, [id]);
if (!id) {
return <p className="error"> ID</p>;
}
return (
<section className="card">
<div className="status-header">
<h2></h2>
<Link to="/"></Link>
</div>
{error ? <p className="error">{error}</p> : null}
{build ? (
<>
<dl className="meta">
<div>
<dt> ID</dt>
<dd>{build.id}</dd>
</div>
<div>
<dt></dt>
<dd>{build.appName}</dd>
</div>
<div>
<dt></dt>
<dd>{build.appNameEn}</dd>
</div>
<div>
<dt>Bundle ID</dt>
<dd>{build.appIdentifier}</dd>
</div>
<div>
<dt></dt>
<dd>
<span className={`badge badge-${build.status}`}>
{statusLabel(build.status)}
</span>
</dd>
</div>
</dl>
{build.status === "completed" ? (
<div className="downloads">
<h3></h3>
<div className="download-actions">
{build.windowsUrl ? (
<a className="button" href={build.windowsUrl} target="_blank" rel="noreferrer">
Windows
</a>
) : (
<span className="muted">Windows </span>
)}
{build.androidUrl ? (
<a className="button secondary" href={build.androidUrl} target="_blank" rel="noreferrer">
Android
</a>
) : (
<span className="muted">Android </span>
)}
</div>
</div>
) : null}
{build.status === "failed" ? (
<div className="error-box">
<p>{build.error ?? "构建失败,请查看 GitHub Actions 日志。"}</p>
{build.actionsUrl ? (
<a href={build.actionsUrl} target="_blank" rel="noreferrer">
Actions
</a>
) : null}
</div>
) : null}
{build.status !== "completed" && build.status !== "failed" ? (
<p className="hint"> GitHub Actions ...</p>
) : null}
</>
) : (
<p className="hint">...</p>
)}
</section>
);
}