From f7a1394cb11503b0ea2e6644f23ec7de24376017 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 14 Jun 2025 15:44:29 +0000 Subject: [PATCH] Refactor: Use Pocketbase for region lookup Replace the local `findSystemRegion` function with a Pocketbase API call to fetch region data. --- src/utils/systemRegionMapping.ts | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/utils/systemRegionMapping.ts b/src/utils/systemRegionMapping.ts index 2ccd06e..3e763df 100644 --- a/src/utils/systemRegionMapping.ts +++ b/src/utils/systemRegionMapping.ts @@ -1,26 +1,26 @@ -// Utility to find which region a system belongs to +// Utility to find which region a system belongs to using pocketbase API export const findSystemRegion = async (systemName: string): Promise => { - // List of all region files we have - const regions = [ - 'Yasna Zakh', 'Molden Heath', 'Period Basis', 'The Bleak Lands', - 'Cloud Ring', 'Paragon Soul' - ]; - - for (const region of regions) { - try { - const response = await fetch(`/${region}.json`); - if (response.ok) { - const systems = await response.json(); - const foundSystem = systems.find((s: any) => s.solarSystemName === systemName); - if (foundSystem) { - return region; - } - } - } catch (error) { - console.warn(`Failed to load region ${region}:`, error); + try { + const pocketbaseUrl = `https://evebase.site.quack-lab.dev/api/collections/regionview/records`; + const response = await fetch(`${pocketbaseUrl}?filter=(sysname%3D'${systemName}')`); + + if (!response.ok) { + console.warn(`Failed to fetch region for system ${systemName}:`, response.status); + return null; } + + const data = await response.json(); + console.log('Region lookup response for', systemName, ':', data); + + if (data.items && data.items.length > 0) { + return data.items[0].sysregion; + } + + console.warn(`No region found for system: ${systemName}`); + return null; + } catch (error) { + console.error(`Error finding region for system ${systemName}:`, error); + return null; } - - return null; };