small redesign of auth view

This commit is contained in:
InsanusMokrassar 2022-01-26 00:55:43 +06:00
parent e4dfdc07fc
commit f3b37cc75a
7 changed files with 46 additions and 42 deletions

View File

@ -77,7 +77,7 @@ fun baseKoin(): Koin {
) )
}, },
{ {
OneStateUIFSMStatesRepo(get(), localStorage) JSUIFSMStatesRepo(get(), localStorage)
} }
) { ) {
first.apply { first.apply {

View File

@ -5,7 +5,7 @@ import dev.inmo.micro_utils.fsm.common.managers.DefaultStatesManagerRepo
import kotlinx.serialization.StringFormat import kotlinx.serialization.StringFormat
import org.w3c.dom.* import org.w3c.dom.*
class OneStateUIFSMStatesRepo( class JSUIFSMStatesRepo(
private val serialFormat: StringFormat, private val serialFormat: StringFormat,
private val storage: Storage, private val storage: Storage,
private val initialState: UIFSMState = DefaultAuthUIFSMState private val initialState: UIFSMState = DefaultAuthUIFSMState

View File

@ -15,7 +15,7 @@ import kotlinx.browser.document
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.dom.* import kotlinx.dom.*
import org.jetbrains.compose.web.attributes.InputType import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.dom.Form import org.jetbrains.compose.web.dom.*
import org.jetbrains.compose.web.dom.Text import org.jetbrains.compose.web.dom.Text
import org.w3c.dom.* import org.w3c.dom.*
@ -32,22 +32,42 @@ class AuthView(
val usernameState = mutableStateOf("") val usernameState = mutableStateOf("")
val passwordState = mutableStateOf("") val passwordState = mutableStateOf("")
val usernameDisabled = mutableStateOf(true) val disabled = mutableStateOf(true)
val passwordDisabled = mutableStateOf(true)
val errorText = mutableStateOf<String?>(null) val errorText = mutableStateOf<String?>(null)
val root = htmlElement.appendElement("div") { val root = htmlElement.appendElement("div") {}
addClass(*UIKitWidth.Fixed.Medium.classes, *UIKitText.Alignment.Center.classes)
}
val composition = renderComposableAndLinkToContext(root) { val composition = renderComposableAndLinkToContext(root) {
val authBtnDisabled = usernameState.value.isBlank() || passwordState.value.isBlank() val authBtnDisabled = usernameState.value.isBlank() || passwordState.value.isBlank()
console.log(authBtnDisabled)
Card( Flex(
Attrs(UIKitWidth.Fixed.Medium), UIKitFlex.Alignment.Horizontal.Center
footerAttrs = Attrs(UIKitText.Alignment.Center), ) {
footer = { Card(
DefaultButton("Authorise", UIKitButton.Type.Primary, disabled = authBtnDisabled) { Attrs(UIKitText.Alignment.Center),
bodyAttrs = Attrs(UIKitWidth.Fixed.Medium),
) {
CardTitle { Text("Log in") }
if (errorText.value != null) {
CardBadge(Attrs(UIKitLabel.Error)) {
Text(errorText.value.toString())
}
}
TextField(
InputType.Text,
usernameState,
disabled,
"Username",
)
TextField(
InputType.Password,
passwordState,
disabled,
"Password"
)
DefaultButton("Authorise", UIKitButton.Type.Primary, UIKitMargin.Small, disabled = authBtnDisabled) {
it.nativeEvent.preventDefault() it.nativeEvent.preventDefault()
val serverUrl = document.location ?.run { "$hostname:$port" } val serverUrl = document.location ?.run { "$hostname:$port" }
if (serverUrl != null) { if (serverUrl != null) {
@ -55,41 +75,25 @@ class AuthView(
} }
} }
} }
) {
CardTitle { Text("Log in") }
TextField(
InputType.Text,
usernameState,
disabledState = usernameDisabled
)
TextField(
InputType.Password,
passwordState,
disabledState = passwordDisabled
)
if (errorText.value != null) {
Label(errorText.value.toString(), Attrs(UIKitLabel.Error, UIKitMargin.Small.Bottom))
}
} }
} }
val viewJob = viewModel.currentState.subscribeSafelyWithoutExceptions(uiScope) { val viewJob = viewModel.currentState.subscribeSafelyWithoutExceptions(uiScope) {
when (it) { when (it) {
is InitAuthUIState -> { is InitAuthUIState -> {
usernameDisabled.value = false disabled.value = false
passwordDisabled.value = false
errorText.value = when (it.showError) { errorText.value = when (it.showError) {
ServerUnavailableAuthUIError -> "Сервер недоступен" ServerUnavailableAuthUIError -> "Server unavailable"
AuthIncorrectAuthUIError -> "Данные некорректны" AuthIncorrectAuthUIError -> {
passwordState.value = ""
"Username or password is incorrect"
}
null -> null null -> null
} }
} }
LoadingAuthUIState -> { LoadingAuthUIState -> {
usernameDisabled.value = true disabled.value = true
passwordDisabled.value = true
errorText.value = null errorText.value = null
} }
AuthorizedAuthUIState -> { AuthorizedAuthUIState -> {

View File

@ -12,8 +12,8 @@
</head> </head>
<body> <body>
<div id="navbar" class="uk-section uk-section-secondary uk-padding-remove"></div> <div id="navbar" class="uk-section uk-section-secondary uk-padding-remove"></div>
<main class="uk-flex"> <main>
<div id="main" class="main-view uk-width-expand"></div> <div id="main" class="main-view"></div>
<div id="modal"></div> <div id="modal"></div>
</main> </main>

View File

@ -1,6 +1,6 @@
[versions] [versions]
jsuikit = "0.0.21" jsuikit = "0.0.27"
compose = "1.0.1" compose = "1.0.1"
microutils = "0.9.4" microutils = "0.9.4"

View File

@ -12,7 +12,7 @@
</head> </head>
<body> <body>
<div id="navbar" class="uk-section uk-section-secondary uk-padding-remove"></div> <div id="navbar" class="uk-section uk-section-secondary uk-padding-remove"></div>
<main class="uk-flex"> <main>
<div id="main" class="main-view"></div> <div id="main" class="main-view"></div>
<div id="modal"></div> <div id="modal"></div>
</main> </main>

File diff suppressed because one or more lines are too long