UI: grey #abcd suffix in geohash peer list; keep base name (and '(you)') styled normally

This commit is contained in:
jack
2025-08-21 03:02:42 +02:00
parent 33fbca67d6
commit 8a269d4fec
+30 -2
View File
@@ -38,10 +38,24 @@ struct GeohashPeopleList: View {
} else { } else {
Image(systemName: "person.fill").font(.system(size: 10)).foregroundColor(textColor) Image(systemName: "person.fill").font(.system(size: 10)).foregroundColor(textColor)
} }
Text(person.displayName + (person.id == myHex ? " (you)" : "")) let (base, suffix) = splitSuffix(from: person.displayName)
let isMe = person.id == myHex
HStack(spacing: 0) {
Text(base)
.font(.system(size: 14, design: .monospaced)) .font(.system(size: 14, design: .monospaced))
.fontWeight(person.id == myHex ? .bold : .regular) .fontWeight(isMe ? .bold : .regular)
.foregroundColor(textColor) .foregroundColor(textColor)
if !suffix.isEmpty {
Text(suffix)
.font(.system(size: 14, design: .monospaced))
.foregroundColor(Color.secondary.opacity(0.6))
}
if isMe {
Text(" (you)")
.font(.system(size: 14, design: .monospaced))
.foregroundColor(textColor)
}
}
Spacer() Spacer()
} }
.padding(.horizontal) .padding(.horizontal)
@@ -60,3 +74,17 @@ struct GeohashPeopleList: View {
} }
#endif #endif
// Helper to split a trailing #abcd suffix
#if os(iOS)
private func splitSuffix(from name: String) -> (String, String) {
guard name.count >= 5 else { return (name, "") }
let suffix = String(name.suffix(5))
if suffix.first == "#", suffix.dropFirst().allSatisfy({ c in
("0"..."9").contains(String(c)) || ("a"..."f").contains(String(c)) || ("A"..."F").contains(String(c))
}) {
let base = String(name.dropLast(5))
return (base, suffix)
}
return (name, "")
}
#endif