Use textFieldState instead of value/onValueChange
This commit is contained in:
@@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.input.TextFieldLineLimits
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Badge
|
||||
import androidx.compose.material.icons.filled.Description
|
||||
@@ -108,10 +109,11 @@ fun CreateProfileScreen(
|
||||
|
||||
TextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
value = createProfileViewModel.createProfileFormState.nameField.text.value,
|
||||
onValueChange = {
|
||||
createProfileViewModel.createProfileFormState.nameField.text.value = it
|
||||
},
|
||||
state = createProfileViewModel.createProfileFormState.nameField.textFieldState,
|
||||
// value = createProfileViewModel.createProfileFormState.nameField.text.value,
|
||||
// onValueChange = {
|
||||
// createProfileViewModel.createProfileFormState.nameField.text.value = it
|
||||
// },
|
||||
isError = createProfileViewModel.createProfileFormState.nameField.errorMessage.value != null,
|
||||
supportingText = createProfileViewModel.createProfileFormState.nameField.errorMessage.value?.let {
|
||||
{
|
||||
@@ -123,7 +125,7 @@ fun CreateProfileScreen(
|
||||
)
|
||||
}
|
||||
},
|
||||
maxLines = 1,
|
||||
lineLimits = TextFieldLineLimits.SingleLine,
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Text,
|
||||
),
|
||||
@@ -155,10 +157,7 @@ fun CreateProfileScreen(
|
||||
|
||||
TextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
value = createProfileViewModel.createProfileFormState.biographyField.text.value,
|
||||
onValueChange = {
|
||||
createProfileViewModel.createProfileFormState.biographyField.text.value = it
|
||||
},
|
||||
state = createProfileViewModel.createProfileFormState.biographyField.textFieldState,
|
||||
isError = createProfileViewModel.createProfileFormState.biographyField.errorMessage.value != null,
|
||||
supportingText = createProfileViewModel.createProfileFormState.biographyField.errorMessage.value?.let {
|
||||
{
|
||||
@@ -170,7 +169,7 @@ fun CreateProfileScreen(
|
||||
)
|
||||
}
|
||||
},
|
||||
maxLines = 1,
|
||||
lineLimits = TextFieldLineLimits.MultiLine(4),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Text,
|
||||
),
|
||||
@@ -208,8 +207,8 @@ fun CreateProfileScreen(
|
||||
if (isInputValid) {
|
||||
createProfileViewModel.createProfileUIState.value =
|
||||
CreateProfileUIState.ConfirmInput(
|
||||
name = createProfileViewModel.createProfileFormState.nameField.text.value,
|
||||
bio = createProfileViewModel.createProfileFormState.biographyField.text.value
|
||||
name = createProfileViewModel.createProfileFormState.nameField.textFieldState.text.toString(),
|
||||
bio = createProfileViewModel.createProfileFormState.biographyField.textFieldState.text.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,10 +69,7 @@ fun SignInToProfileScreen(
|
||||
|
||||
TextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
value = signInToProfileViewModel.signInToProfileFormState.textField.text.value,
|
||||
onValueChange = {
|
||||
signInToProfileViewModel.signInToProfileFormState.textField.text.value = it
|
||||
},
|
||||
state = signInToProfileViewModel.signInToProfileFormState.textField.textFieldState,
|
||||
isError = signInToProfileViewModel.signInToProfileFormState.textField.errorMessage.value != null,
|
||||
supportingText = signInToProfileViewModel.signInToProfileFormState.textField.errorMessage.value?.let {
|
||||
{
|
||||
@@ -114,13 +111,13 @@ fun SignInToProfileScreen(
|
||||
when (credentialEntity) {
|
||||
is NSec -> {
|
||||
SignInToProfileUIState.ConfirmNsecSignIn(
|
||||
nsec = signInToProfileViewModel.signInToProfileFormState.textField.text.value,
|
||||
nsec = signInToProfileViewModel.signInToProfileFormState.textField.textFieldState.text.toString(),
|
||||
hexKey = credentialEntity.hex
|
||||
)
|
||||
}
|
||||
is NPub -> {
|
||||
SignInToProfileUIState.ConfirmNpubSignIn(
|
||||
npub = signInToProfileViewModel.signInToProfileFormState.textField.text.value,
|
||||
npub = signInToProfileViewModel.signInToProfileFormState.textField.textFieldState.text.toString(),
|
||||
hexKey = credentialEntity.hex
|
||||
)
|
||||
}
|
||||
|
||||
@@ -128,10 +128,7 @@ fun WriteNewNoteScreen(
|
||||
|
||||
TextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
value = writeNewNoteViewModel.writeNewNoteFormState.textField.text.value,
|
||||
onValueChange = {
|
||||
writeNewNoteViewModel.writeNewNoteFormState.textField.text.value = it
|
||||
},
|
||||
state = writeNewNoteViewModel.writeNewNoteFormState.textField.textFieldState,
|
||||
isError = writeNewNoteViewModel.writeNewNoteFormState.textField.errorMessage.value != null,
|
||||
supportingText = writeNewNoteViewModel.writeNewNoteFormState.textField.errorMessage.value?.let {
|
||||
{
|
||||
|
||||
@@ -48,14 +48,14 @@ class CreateProfileViewModel(
|
||||
)
|
||||
|
||||
fun validateInput(): Boolean {
|
||||
if (createProfileFormState.nameField.text.value.isBlank()) {
|
||||
if (createProfileFormState.nameField.textFieldState.text.isBlank()) {
|
||||
createProfileFormState.nameField.errorMessage.value = "Please input a display name"
|
||||
return false
|
||||
} else {
|
||||
createProfileFormState.nameField.errorMessage.value = null
|
||||
}
|
||||
|
||||
if (createProfileFormState.biographyField.text.value.isBlank()) {
|
||||
if (createProfileFormState.biographyField.textFieldState.text.isBlank()) {
|
||||
createProfileFormState.biographyField.errorMessage.value = "Please input a biography"
|
||||
return false
|
||||
} else {
|
||||
@@ -77,8 +77,8 @@ class CreateProfileViewModel(
|
||||
|
||||
nostrRepository.createNewProfile(
|
||||
publicKey,
|
||||
name = createProfileFormState.nameField.text.value,
|
||||
biography = createProfileFormState.biographyField.text.value,
|
||||
name = createProfileFormState.nameField.textFieldState.text.toString(),
|
||||
biography = createProfileFormState.biographyField.textFieldState.text.toString(),
|
||||
onError = {
|
||||
createProfileUIState.value = CreateProfileUIState.Error
|
||||
},
|
||||
|
||||
@@ -50,7 +50,7 @@ class SignInToProfileViewModel(
|
||||
)
|
||||
|
||||
fun validateCredential(): Entity? {
|
||||
return signInToProfileFormState.textField.text.value.let { credentialText ->
|
||||
return signInToProfileFormState.textField.textFieldState.text.toString().let { credentialText ->
|
||||
if (credentialText.isBlank()) {
|
||||
signInToProfileFormState.textField.errorMessage.value = "Please input a credential"
|
||||
return null
|
||||
@@ -58,7 +58,7 @@ class SignInToProfileViewModel(
|
||||
signInToProfileFormState.textField.errorMessage.value = null
|
||||
}
|
||||
|
||||
Nip19Parser.uriToRoute(signInToProfileFormState.textField.text.value)?.entity
|
||||
Nip19Parser.uriToRoute(signInToProfileFormState.textField.textFieldState.text.toString())?.entity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ class WriteNewNoteViewModel(
|
||||
localProfile = localProfile,
|
||||
inReplyToNostrEvent = inReplyToNostrEvent,
|
||||
quotedNostrEvent = quotedNostrEvent,
|
||||
text = writeNewNoteFormState.textField.text.value,
|
||||
text = writeNewNoteFormState.textField.textFieldState.text.toString(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ class WriteNewNoteViewModel(
|
||||
}
|
||||
|
||||
fun validateInput(): Boolean {
|
||||
if (writeNewNoteFormState.textField.text.value.isBlank()) {
|
||||
if (writeNewNoteFormState.textField.textFieldState.text.isBlank()) {
|
||||
writeNewNoteFormState.textField.errorMessage.value = "Please input a note"
|
||||
return false
|
||||
} else {
|
||||
@@ -138,7 +138,7 @@ class WriteNewNoteViewModel(
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
nostrRepository.createNewTextNote(
|
||||
publicKey = SeedManager.activePublicKey().toHexKey(),
|
||||
textInput = writeNewNoteFormState.textField.text.value,
|
||||
textInput = writeNewNoteFormState.textField.textFieldState.text.toString(),
|
||||
inReplyToNostrEvent = inReplyToNostrEvent,
|
||||
quotedNostrEvent = quotedNostrEvent,
|
||||
onError = {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package ac.cord.auxiliary.compose.ui.view.state.form
|
||||
|
||||
import androidx.compose.foundation.text.input.TextFieldState
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
|
||||
data class TextField(
|
||||
val text: MutableState<String> = mutableStateOf(""),
|
||||
val textFieldState: TextFieldState = TextFieldState(),
|
||||
val errorMessage: MutableState<String?> = mutableStateOf(null)
|
||||
)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ac.cord.auxiliary.compose.ui.view.state.form
|
||||
|
||||
import androidx.compose.foundation.text.input.TextFieldState
|
||||
|
||||
data class WriteNewNoteFormState(
|
||||
val textField: TextField = TextField(),
|
||||
)
|
||||
Reference in New Issue
Block a user