Refactor: Use Pocketbase for region lookup
Replace the local `findSystemRegion` function with a Pocketbase API call to fetch region data.
This commit is contained in:
@@ -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<string | null> => {
|
||||
// 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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user