Skip to content

Commit

Permalink
use full address for address search display value
Browse files Browse the repository at this point in the history
  • Loading branch information
thatmattlove committed Sep 16, 2024
1 parent 28dc3ef commit f6a3c71
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
15 changes: 3 additions & 12 deletions lib/address-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export interface SearchResult {
displayName: string;
description: string;
formValue: SearchResultValue;
}

Expand All @@ -21,11 +20,9 @@ export function isSearchResults(data: unknown): data is SearchResult[] {
data[0] !== null &&
"displayName" in data[0] &&
"formValue" in data[0] &&
"description" in data[0] &&
typeof data[0].displayName === "string" &&
typeof data[0].formValue === "object" &&
data[0].formValue !== null &&
typeof data[0].description === "string"
data[0].formValue !== null
);
}
return Array.isArray(data);
Expand All @@ -47,14 +44,8 @@ export function isMapboxCity(data: Suggestion): boolean {
}

export function formatCity(data: Suggestion): SearchResult {
const displayName = [data.name, data.context.region.region_code].join(", ");
let addressParts: string[] = [];
if (typeof data.context.district !== "undefined") {
addressParts = [...addressParts, data.context.district.name];
}
addressParts = [...addressParts, data.context.region.name, data.context.country.name];
const description = addressParts.join(", ");
return { displayName, description, formValue: getContextValue(data.context) };
const displayName = data.full_address;
return { displayName, formValue: getContextValue(data.context) };
}

export function getContextValue(data: Context): SearchResultValue {
Expand Down
3 changes: 1 addition & 2 deletions lib/server/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ export async function search(
return results;
}
const results: SearchResult[] = data.suggestions.map(suggestion => ({
displayName: suggestion.name,
displayName: suggestion.full_address,
formValue: getContextValue(suggestion.context),
description: suggestion.full_address,
}));
return results;
}
1 change: 0 additions & 1 deletion src/hooks/use-address-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async function queryFn(search: string, locationType: LocationType): Promise<Sele
return data.map(d => ({
label: d.displayName,
value: JSON.stringify(d.formValue),
description: d.description,
}));
}
throw new Error(data);
Expand Down

0 comments on commit f6a3c71

Please sign in to comment.