feat(#19): Sort by hubs

This commit is contained in:
Sirttas
2026-07-09 19:16:06 +02:00
parent 81250953eb
commit 52addba909
3 changed files with 39 additions and 29 deletions
+16 -1
View File
@@ -5,11 +5,26 @@ export type MarketLocation = MarketLocationResponse;
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 universeApi.searchLocations(search).then(r => r.data);
locations.forEach(l => cache.set(l.id, l));
return locations;
return locations.toSorted((a, b) => hubRank(a.id) - hubRank(b.id));
};