mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 08:51:16 -05:00
feat: Add street address to locations
Adds a street_address column to the locations table and updates the LocationSearch component to capture, store, and display full street addresses. This includes database migration, interface updates, and formatter logic.
This commit is contained in:
64
src/lib/locationFormatter.ts
Normal file
64
src/lib/locationFormatter.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Location Formatting Utilities
|
||||
*
|
||||
* Centralized utilities for formatting location data consistently across the app.
|
||||
*/
|
||||
|
||||
export interface LocationData {
|
||||
street_address?: string | null;
|
||||
city?: string | null;
|
||||
state_province?: string | null;
|
||||
country?: string | null;
|
||||
postal_code?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format location for display
|
||||
* @param location - Location data object
|
||||
* @param includeStreet - Whether to include street address in the output
|
||||
* @returns Formatted location string or null if no location data
|
||||
*/
|
||||
export function formatLocationDisplay(
|
||||
location: LocationData | null | undefined,
|
||||
includeStreet: boolean = false
|
||||
): string | null {
|
||||
if (!location) return null;
|
||||
|
||||
const parts: string[] = [];
|
||||
|
||||
if (includeStreet && location.street_address) {
|
||||
parts.push(location.street_address);
|
||||
}
|
||||
|
||||
if (location.city) {
|
||||
parts.push(location.city);
|
||||
}
|
||||
|
||||
if (location.state_province) {
|
||||
parts.push(location.state_province);
|
||||
}
|
||||
|
||||
if (location.country) {
|
||||
parts.push(location.country);
|
||||
}
|
||||
|
||||
return parts.length > 0 ? parts.join(', ') : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format full address including street
|
||||
* @param location - Location data object
|
||||
* @returns Formatted full address or null if no location data
|
||||
*/
|
||||
export function formatFullAddress(location: LocationData | null | undefined): string | null {
|
||||
return formatLocationDisplay(location, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format location without street address (city, state, country only)
|
||||
* @param location - Location data object
|
||||
* @returns Formatted location without street or null if no location data
|
||||
*/
|
||||
export function formatLocationShort(location: LocationData | null | undefined): string | null {
|
||||
return formatLocationDisplay(location, false);
|
||||
}
|
||||
Reference in New Issue
Block a user