Factory: project dropdown
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5572cad54
commit
e1baf6f00f
6 files changed
+58
-12
No files matched your search
@@ -170,7 +170,19 @@ export function Factory({ onMenu }: { onMenu: () => void }) {
|
||||
function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
const t = useT();
|
||||
const [data, setData] = useState<Overview>();
|
||||
const [repo, setRepo] = useState<string>("");
|
||||
const [repo, setRepoState] = useState<string>(() => {
|
||||
try {
|
||||
return localStorage.getItem("codecraft.factoryRepo") ?? "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
const setRepo = (r: string) => {
|
||||
setRepoState(r);
|
||||
try {
|
||||
localStorage.setItem("codecraft.factoryRepo", r);
|
||||
} catch {}
|
||||
};
|
||||
const [sel, setSel] = useState<string>("");
|
||||
const [now, setNow] = useState(Date.now());
|
||||
const [busy, setBusy] = useState(false);
|
||||
@@ -189,6 +201,11 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
return () => clearInterval(h);
|
||||
}, []);
|
||||
|
||||
// A remembered project that no longer exists falls back to "all".
|
||||
useEffect(() => {
|
||||
if (data && repo && !data.repos.some((r) => r.url === repo)) setRepo("");
|
||||
}, [data, repo]);
|
||||
|
||||
const newProject = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
@@ -383,26 +400,33 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
</div>
|
||||
|
||||
<div className="factory-repos">
|
||||
<button className={`factory-repo ${repo === "" ? "active" : ""}`} onClick={() => setRepo("")}>
|
||||
<b>{t("factory.allRepos")}</b>
|
||||
<span className="hint">{t("factory.kpi.issues", { n: data.issues.length })}</span>
|
||||
</button>
|
||||
{data.repos.map((r) => {
|
||||
const mine = data.issues.filter((i) => i.repo === r.url);
|
||||
<select className="factory-repo-select" value={repo} onChange={(e) => setRepo(e.target.value)} aria-label={t("factory.project")}>
|
||||
<option value="">
|
||||
{t("factory.allRepos")} ({data.issues.length})
|
||||
</option>
|
||||
{data.repos.map((r) => (
|
||||
<option key={r.url} value={r.url}>
|
||||
{repoName(r.url)}
|
||||
{r.version ? ` · v${r.version}` : ""} ({data.issues.filter((i) => i.repo === r.url).length}){r.enabled ? "" : " – off"}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{(() => {
|
||||
const r = data.repos.find((x) => x.url === repo);
|
||||
if (!r) return null;
|
||||
return (
|
||||
<button key={r.url} className={`factory-repo ${repo === r.url ? "active" : ""} ${r.enabled ? "" : "off"}`} onClick={() => setRepo(r.url)}>
|
||||
<b>{repoName(r.url)}</b>
|
||||
<span className="factory-repo-info">
|
||||
<span className="chip">{KIND_NAME[r.kind] ?? r.kind}</span>
|
||||
{r.version && <span className="chip ok mono">v{r.version}</span>}
|
||||
<span className="hint">
|
||||
{r.running > 0 && <span className="factory-pulse" />}
|
||||
{t("factory.repoLine", { n: mine.length, run: r.running })}
|
||||
{t("factory.repoLine", { n: data.issues.filter((i) => i.repo === r.url).length, run: r.running })}
|
||||
</span>
|
||||
<span className="hint mono">{PHASES.map((p) => r.models[p] || "·").map((m) => m.split("/").pop()).join(" → ")}</span>
|
||||
{!r.has_token && <span className="chip warn">{t("factory.noToken")}</span>}
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
})()}
|
||||
<button className="small primary" onClick={newProject} disabled={busy}>
|
||||
<Icon name="plus" /> {t("factory.newProject")}
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user