diff --git a/packages/web_ui/src/components/ModsPage.tsx b/packages/web_ui/src/components/ModsPage.tsx index 13d98490..38924d07 100644 --- a/packages/web_ui/src/components/ModsPage.tsx +++ b/packages/web_ui/src/components/ModsPage.tsx @@ -28,6 +28,9 @@ const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" // Define the allowed Factorio versions based on the lib schema type FactorioVersion = Static<(typeof lib.ModPortalGetAllRequest)["allowedVersions"][number]>; +// Type alias for the mod structure derived from the library response +type ModPortalModType = InstanceType["mods"][number]; + function ImportModPackButton() { let control = useContext(ControlContext); let navigate = useNavigate(); @@ -136,27 +139,6 @@ function CreateModPackButton() { ; } -// Define a basic type for the mod data we expect back from the new backend request -// This should ideally match the structure returned by the backend. -// We reuse the ModPortalMod structure name for convenience, but it's fetched via backend. -interface ModPortalMod { - name: string; - title: string; - owner: string; - summary: string; - downloads_count: number; - category: string; - score?: number; - latest_release?: { - download_url: string; - file_name: string; - info_json: { factorio_version: string; }; - released_at: string; - version: string; - sha1: string; - }; -} - function SearchModsButton() { const control = useContext(ControlContext); const account = useAccount(); @@ -166,7 +148,7 @@ function SearchModsButton() { const [factorioVersion, setFactorioVersion] = useState("2.0"); // State for all mods fetched from backend - const [allMods, setAllMods] = useState([]); + const [allMods, setAllMods] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); @@ -214,14 +196,11 @@ function SearchModsButton() { setError(null); let canceled = false; - // Use the hypothetical new backend request control.send( - // Factorio version state now matches the required type new lib.ModPortalGetAllRequest(factorioVersion) ).then((response: any) => { if (canceled) { return; } - // *** Backend Change Needed: Ensure the response has a 'mods' array *** - setAllMods(response?.mods || []); // Added optional chaining + setAllMods(response.mods || []); setLoading(false); }).catch(err => { if (canceled) { return; } @@ -254,8 +233,8 @@ function SearchModsButton() { // Apply sorting if (sort && sortOrder) { filtered = [...filtered].sort((a, b) => { - let aValue: any = a[sort as keyof ModPortalMod] ?? ""; - let bValue: any = b[sort as keyof ModPortalMod] ?? ""; + let aValue: any = a[sort as keyof ModPortalModType] ?? ""; + let bValue: any = b[sort as keyof ModPortalModType] ?? ""; // Handle specific types if necessary (e.g., numbers, dates) if (sort === "downloads_count") { @@ -354,7 +333,6 @@ function SearchModsButton() { , - // Remove explicit search button as form updates trigger search/filter ]} >
@@ -431,14 +407,13 @@ function SearchModsButton() { ) :

No release information available.

} - {/* Download button logic remains the same, assuming backend handles downloads */} - {account.hasPermission("core.mod.download") && record.latest_release && ( + {account.hasPermission("core.mod.download_from_portal") && record.latest_release && ( - {account.hasPermission("core.mod.download") && record.latest_release && ( + {account.hasPermission("core.mod.download_from_portal") && record.latest_release && (