chore: Include less info per location to reduce filesize

This commit is contained in:
Florian Zia 2024-02-07 11:58:06 +01:00
Родитель d3b984b019
Коммит 25301bf7f8
Не найден ключ, соответствующий данной подписи
6 изменённых файлов: 23 добавлений и 28 удалений

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -34,10 +34,11 @@ function getLocationsByQuery(searchQuery: string) {
}
const locationNames = locationData.data.map((location: RelevantLocation) => {
const { name, stateCode, countryCode, alternateNames } = location;
const alternateNamesJoined = alternateNames ? alternateNames.join(" ") : "";
const { n, s, a } = location;
const alternateNamesJoined = a ? a.join(" ") : "";
const countryCode = "USA";
return `${name} ${stateCode} ${countryCode} ${alternateNamesJoined}`;
return `${n} ${s} ${countryCode} ${alternateNamesJoined}`;
});
// For search options see: https://github.com/leeoniya/uFuzzy#options
@ -79,7 +80,7 @@ function getLocationsByQuery(searchQuery: string) {
.slice(0, locationSplitIndex)
.sort(
(a: RelevantLocation, b: RelevantLocation) =>
Number(b.population) - Number(a.population),
Number(b.p ?? 0) - Number(a.p ?? 0),
),
...resultsOrdered.slice(locationSplitIndex + 1),
];

Просмотреть файл

@ -835,14 +835,11 @@ export type LocationData = [
];
export interface RelevantLocation {
id: string;
name: string;
stateCode: string;
countryCode: string;
featureClass: string;
featureCode: string;
population: string;
alternateNames?: Array<string>;
id: string; // GeoName location ID
n: string; // location name
s: string; // state code
p?: string; // population
a?: Array<string>; // alternate location names
}
export interface RelevantLocationAlternate {

Просмотреть файл

@ -21,8 +21,8 @@ export function getDetailsFromLocationString(locationString: string) {
}
function getLocationString(location: RelevantLocation) {
const { name, stateCode, countryCode } = location;
return `${name}, ${stateCode}, ${countryCode}`;
const { n: name, s: stateCode } = location;
return `${name}, ${stateCode}, USA`;
}
function getLocationStringByKey(

Просмотреть файл

@ -14,15 +14,13 @@ export const useLocationSuggestions: typeof ogUseLocationSuggestions = () => {
items: [
{
id: "4553433",
name: "Tulsa",
stateCode: "OK",
countryCode: "USA",
n: "Tulsa",
s: "OK",
},
{
id: "5318313",
name: "Tucson",
stateCode: "AZ",
countryCode: "USA",
n: "Tucson",
s: "AZ",
},
] as RelevantLocation[],
setFilterText: mockSetFilterText,

Просмотреть файл

@ -261,15 +261,14 @@ try {
relevantLocations.push({
id: geonameId,
// switch names if an alternate name is the preferred location name
name: preferredName ? preferredName.name : name,
stateCode: admin1Code,
countryCode: "USA",
featureClass,
featureCode,
population,
n: preferredName ? preferredName.name : name,
s: admin1Code,
...(Number(population) > 0 && {
p: population,
}),
...(alternateNames &&
alternateNames.length > 0 && {
alternateNames: alternateNamesFinal,
a: alternateNamesFinal,
}),
});
}