Spaces:
Running
Running
feat(ui): labels/ordering/platform hints for Linux AppImage, Arch PKGBUILD, MCP; API tests; README
d6faa34 Download frontend/src/components/TargetPicker.tsx from 2Btainment/spaceforge: direct link, hf CLI and curl.
- Browser
- Download file 3.43 kB
-
https://huggingface.co/spaces/2Btainment/spaceforge/resolve/main/frontend/src/components/TargetPicker.tsx
- Command line
-
hf download hf://spaces/2Btainment/spaceforge/frontend/src/components/TargetPicker.tsx
-
curl -L -o TargetPicker.tsx https://huggingface.co/spaces/2Btainment/spaceforge/resolve/main/frontend/src/components/TargetPicker.tsx
3.43 kB
| import type { CompatLevel, TargetInfo } from "../types"; | |
| import { ModeBadge } from "./ModeBadge"; | |
| import { t } from "../i18n"; | |
| /** Canonical labels for the newer targets (backend label wins when present). */ | |
| export const TARGET_LABELS: Record<string, string> = { | |
| linux_appimage: "Linux AppImage", | |
| arch_pkgbuild: "Arch Linux (PKGBUILD)", | |
| mcp: "MCP Server / Config", | |
| windows_portable: "Windows Portable", | |
| }; | |
| export function targetLabel(id: string, label?: string): string { | |
| return label || TARGET_LABELS[id] || id; | |
| } | |
| /** Real targets first, disabled stubs last (stable within each group). */ | |
| export function orderTargets(targets: TargetInfo[]): TargetInfo[] { | |
| return [...targets].sort((a, b) => Number(!!a.stub) - Number(!!b.stub)); | |
| } | |
| function CompatChip({ level, label }: { level: CompatLevel; label: string }) { | |
| const icon = level === "ok" ? "✓" : level === "warn" ? "⚠" : "✗"; | |
| return ( | |
| <span className={`compat ${level}`} title={label}> | |
| {icon} {label} | |
| </span> | |
| ); | |
| } | |
| export function TargetPicker({ | |
| targets, | |
| selected, | |
| onChange, | |
| }: { | |
| targets: TargetInfo[]; | |
| selected: Set<string>; | |
| onChange: (next: Set<string>) => void; | |
| }) { | |
| const m = t(); | |
| const platform: Record<string, string> = { | |
| linux_appimage: m.platformAppImage, | |
| arch_pkgbuild: m.platformPkgbuild, | |
| mcp: m.platformMcp, | |
| }; | |
| return ( | |
| <div className="targets"> | |
| {orderTargets(targets).map((tg) => { | |
| const disabled = !tg.available; | |
| const checked = selected.has(tg.id); | |
| const c = tg.compat; | |
| return ( | |
| <div key={tg.id} className={`target ${disabled ? "disabled" : ""}`} data-testid={`target-${tg.id}`}> | |
| <input | |
| type="checkbox" | |
| disabled={disabled} | |
| checked={checked} | |
| onChange={(e) => { | |
| const next = new Set(selected); | |
| if (e.target.checked) next.add(tg.id); | |
| else next.delete(tg.id); | |
| onChange(next); | |
| }} | |
| /> | |
| <div> | |
| <label> | |
| {targetLabel(tg.id, tg.label)} <ModeBadge mode={tg.mode} /> | |
| </label> | |
| {platform[tg.id] ? <div className="platform">{platform[tg.id]}</div> : null} | |
| <div className="reason">{tg.reason}</div> | |
| {c ? ( | |
| <div className="compat-row"> | |
| {c.project ? ( | |
| <CompatChip | |
| level={c.project} | |
| label={c.project === "ok" ? m.compatProjectOk : m.compatProjectNo} | |
| /> | |
| ) : null} | |
| {c.apk ? ( | |
| <CompatChip | |
| level={c.apk} | |
| label={c.apk === "ok" ? m.compatApkOk : m.compatApkWarn} | |
| /> | |
| ) : null} | |
| {c.gpu_local ? ( | |
| <CompatChip | |
| level={c.gpu_local} | |
| label={ | |
| c.gpu_local === "no" ? m.compatGpuNo : m.compatGpuWarn | |
| } | |
| /> | |
| ) : null} | |
| </div> | |
| ) : null} | |
| {tg.stub ? <div className="reason">{m.stubNote}</div> : null} | |
| </div> | |
| <div>{disabled ? <span className="hint">{m.unavailable}</span> : null}</div> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| ); | |
| } | |