31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import {locationApi} from '@/mammon/mammonService';
|
|
import type {DockableLocationResponse} from '@/generated/mammon';
|
|
|
|
export type MarketLocation = DockableLocationResponse;
|
|
|
|
const cache = new Map<number, MarketLocation>();
|
|
|
|
const defaultHubIds = [
|
|
60003760, // Jita IV - Moon 4 - Caldari Navy Assembly Plant
|
|
60008494, // Amarr VIII (Oris) - Emperor Family Academy
|
|
60011866, // Dodixie IX - Moon 20 - Federation Navy Assembly Plant
|
|
60004588, // Rens VI - Moon 8 - Brutor Tribe Treasury
|
|
60005686, // Hek VIII - Moon 12 - Boundless Creation Factory
|
|
];
|
|
|
|
const hubRank = (id: number) => {
|
|
const rank = defaultHubIds.indexOf(id);
|
|
return rank < 0 ? defaultHubIds.length : rank;
|
|
};
|
|
|
|
export const isDefaultHub = (id: number): boolean => defaultHubIds.includes(id);
|
|
|
|
export const searchMarketLocations = async (search: string): Promise<MarketLocation[]> => {
|
|
if (search.length === 0) {
|
|
return [];
|
|
}
|
|
const locations = await locationApi.searchLocations(search).then(r => r.data);
|
|
locations.forEach(l => cache.set(l.id, l));
|
|
return locations.toSorted((a, b) => hubRank(a.id) - hubRank(b.id));
|
|
};
|