refactor: centralize city prefix stripping logic and standardize location and member-since UI styling
This commit is contained in:
@@ -184,10 +184,8 @@ class AgentDetailState {
|
||||
if (fvStates != null) parts.addAll(fvStates.map(_normalizeStateCode));
|
||||
if (fvCities != null) {
|
||||
for (final c in fvCities) {
|
||||
// City values carry a state prefix (e.g. "ne_adams"); strip it for display.
|
||||
final cleaned = _stripCityStatePrefix(c);
|
||||
if (!parts.any((p) => p.toLowerCase() == cleaned.toLowerCase())) {
|
||||
parts.add(cleaned);
|
||||
if (!parts.any((p) => p.toLowerCase() == c.toLowerCase())) {
|
||||
parts.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,7 +196,7 @@ class AgentDetailState {
|
||||
parts.add(_normalizeStateCode(agent!.state!));
|
||||
}
|
||||
if (agent!.city != null && agent!.city!.isNotEmpty) {
|
||||
parts.add(_stripCityStatePrefix(agent!.city!));
|
||||
parts.add(agent!.city!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,23 +218,6 @@ class AgentDetailState {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
/// Strip the state-code prefix from a city value (e.g. "Ne Adams" / "ne_adams" → "Adams").
|
||||
/// After removing the prefix, title-case the remainder.
|
||||
String _stripCityStatePrefix(String raw) {
|
||||
final trimmed = raw.trim();
|
||||
// Snake-case with a 2-letter state prefix: ne_adams, co_aetna_estates
|
||||
final snakeMatch = RegExp(r'^[a-z]{2}_', caseSensitive: false).firstMatch(trimmed);
|
||||
if (snakeMatch != null) {
|
||||
return titleCase(trimmed.substring(snakeMatch.end));
|
||||
}
|
||||
// Title-cased with a 2-letter prefix token: "Ne Adams", "Co Aetna Estates"
|
||||
final spaceMatch = RegExp(r'^[A-Za-z]{2}\s+').firstMatch(trimmed);
|
||||
if (spaceMatch != null) {
|
||||
return trimmed.substring(spaceMatch.end);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
/// Combined location text for single-line display.
|
||||
String get locationText {
|
||||
final parts = locationParts;
|
||||
@@ -245,14 +226,28 @@ class AgentDetailState {
|
||||
}
|
||||
|
||||
/// Extract all values from a field as a list of title-cased strings.
|
||||
/// For city fields, strip the 2-letter state prefix before title-casing
|
||||
/// (matches web's `stripCityPrefix`: "ne_adams" → "Adams").
|
||||
static List<String>? _extractAllValuesAsList(AgentFieldValue fv) {
|
||||
final isCity = (fv.fieldSlug.toLowerCase() == 'city' ||
|
||||
fv.fieldSlug.toLowerCase() == 'city_name');
|
||||
|
||||
String format(String raw) {
|
||||
var s = raw;
|
||||
if (isCity) {
|
||||
// Strip 2-letter state prefix: "ne_adams" → "adams", "co_aetna_estates" → "aetna_estates"
|
||||
s = s.replaceFirst(RegExp(r'^[a-z]{2}_', caseSensitive: false), '');
|
||||
}
|
||||
return titleCase(s);
|
||||
}
|
||||
|
||||
if (fv.jsonValue is List && (fv.jsonValue as List).isNotEmpty) {
|
||||
return (fv.jsonValue as List)
|
||||
.map((v) => titleCase(v.toString()))
|
||||
.map((v) => format(v.toString()))
|
||||
.toList();
|
||||
}
|
||||
if (fv.textValue != null && fv.textValue!.isNotEmpty) {
|
||||
return [titleCase(fv.textValue!)];
|
||||
return [format(fv.textValue!)];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user