mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 15:05:20 +00:00
Add nickname validation to prevent empty names
- Validate nickname only when field loses focus or on submit - Replace empty nicknames with anon+random 4 digits (e.g. anon3847) - Remove auto-save timer to prevent validation while typing - Add FocusState to detect when user exits the field
This commit is contained in:
@@ -25,6 +25,7 @@ struct ContentView: View {
|
||||
@State private var showMessageActions = false
|
||||
@State private var selectedMessageSender: String?
|
||||
@State private var selectedMessageSenderID: String?
|
||||
@FocusState private var isNicknameFieldFocused: Bool
|
||||
|
||||
private var backgroundColor: Color {
|
||||
colorScheme == .dark ? Color.black : Color.white
|
||||
@@ -727,11 +728,15 @@ struct ContentView: View {
|
||||
.font(.system(size: 14, design: .monospaced))
|
||||
.frame(maxWidth: 100)
|
||||
.foregroundColor(textColor)
|
||||
.onChange(of: viewModel.nickname) { _ in
|
||||
viewModel.saveNickname()
|
||||
.focused($isNicknameFieldFocused)
|
||||
.onChange(of: isNicknameFieldFocused) { isFocused in
|
||||
if !isFocused {
|
||||
// Only validate when losing focus
|
||||
viewModel.validateAndSaveNickname()
|
||||
}
|
||||
}
|
||||
.onSubmit {
|
||||
viewModel.saveNickname()
|
||||
viewModel.validateAndSaveNickname()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user