a little updates

This commit is contained in:
2022-05-07 21:54:19 +06:00
parent a3ff08af27
commit 55d0e1b55f
10 changed files with 53 additions and 57 deletions
features
auth
client
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
jsMain
kotlin
dev
inmo
postssystem
features
auth
common
common
src
commonMain
kotlin
dev
inmo
postssystem
features
roles
common
src
commonMain
kotlin
dev
inmo
postssystem
features
roles
common
manager
common
src
commonMain
kotlin
dev
inmo
postssystem
features
roles
manager
targets/telegram
loader
server
src
jvmMain
kotlin
dev
inmo
postssystem
targets
telegram
loader
publication
server
src
jvmMain
kotlin
dev
inmo
postssystem
targets
telegram

@ -16,9 +16,5 @@ kotlin {
api project(":postssystem.features.auth.common")
}
}
clientMain {
dependencies {
}
}
}
}

@ -9,6 +9,8 @@ import dev.inmo.micro_utils.common.Either
import dev.inmo.micro_utils.common.either
import dev.inmo.micro_utils.repos.*
import dev.inmo.postssystem.features.auth.client.createAuthorizedFeaturesDIModule
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.AuthIncorrect
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.ServerUnavailable
import dev.inmo.postssystem.features.common.common.DBDropper
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
@ -83,8 +85,8 @@ data class DefaultAuthSettings(
currentModule ?.let { koin.loadModules(listOf(currentModule)) }
}
return when {
!serverAvailable -> ServerUnavailableAuthUIError
!authCorrect -> AuthIncorrectAuthUIError
!serverAvailable -> ServerUnavailable
!authCorrect -> AuthIncorrect
else -> {
_authorizedDIModule.value = newModule
null

@ -3,18 +3,23 @@ package dev.inmo.postssystem.features.auth.client.ui
import kotlinx.serialization.Serializable
@Serializable
sealed class AuthUIError
@Serializable
object ServerUnavailableAuthUIError : AuthUIError()
@Serializable
object AuthIncorrectAuthUIError : AuthUIError()
sealed class AuthUIError {
@Serializable
object ServerUnavailable : AuthUIError()
@Serializable
object AuthIncorrect : AuthUIError()
}
@Serializable
sealed class AuthUIState
@Serializable
data class InitAuthUIState(val showError: AuthUIError? = null) : AuthUIState()
val DefaultInitAuthUIState = InitAuthUIState()
@Serializable
object LoadingAuthUIState : AuthUIState()
@Serializable
object AuthorizedAuthUIState : AuthUIState()
sealed class AuthUIState {
@Serializable
data class Init(val showError: AuthUIError? = null) : AuthUIState()
@Serializable
object Loading : AuthUIState()
@Serializable
object Authorized : AuthUIState()
companion object {
val DefaultInit = Init()
}
}

@ -9,26 +9,26 @@ import kotlinx.coroutines.launch
class DefaultAuthUIModel(
private val scope: CoroutineScope,
private val authSettings: AuthSettings
) : AbstractUIModel<AuthUIState>(LoadingAuthUIState), AuthUIModel {
) : AbstractUIModel<AuthUIState>(AuthUIState.Loading), AuthUIModel {
init {
scope.launch {
_currentState.value = LoadingAuthUIState
_currentState.value = AuthUIState.Loading
authSettings.loadingJob.join()
if (authSettings.authorizedDIModule.value == null) {
_currentState.value = DefaultInitAuthUIState
_currentState.value = AuthUIState.DefaultInit
} else {
_currentState.value = AuthorizedAuthUIState
_currentState.value = AuthUIState.Authorized
}
}
}
override suspend fun initAuth(serverUrl: String, creds: AuthCreds) {
_currentState.value = LoadingAuthUIState
_currentState.value = AuthUIState.Loading
val authError = authSettings.auth(serverUrl, creds)
if (authError == null) {
_currentState.value = AuthorizedAuthUIState
_currentState.value = AuthUIState.Authorized
} else {
_currentState.value = InitAuthUIState(authError)
_currentState.value = AuthUIState.Init(authError)
}
}

@ -9,6 +9,8 @@ import dev.inmo.postssystem.features.auth.client.ui.*
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
import dev.inmo.micro_utils.fsm.common.StatesMachine
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.AuthIncorrect
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.ServerUnavailable
import dev.inmo.postssystem.features.common.common.*
import dev.inmo.postssystem.features.common.common.ui.JSView
import dev.inmo.postssystem.features.common.common.ui.fsm.*
@ -19,9 +21,11 @@ import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.dom.Text
import org.w3c.dom.*
@ExperimentalStdlibApi
@EagerInitialization
val loader = DefaultModuleLoader {
factory { AuthView(get(), get(DefaultQualifiers.UIScopeQualifier), getAllDistinct()) }
singleWithRandomQualifier<UIFSMHandler.Registrator> {
singleWithRandomQualifier {
UIFSMHandler.Registrator {
strictlyOn(get<AuthView>())
}
@ -64,13 +68,13 @@ class AuthView(
}
}
TextField(
StandardInput(
InputType.Text,
usernameState,
disabled,
"Username",
)
TextField(
StandardInput(
InputType.Password,
passwordState,
disabled,
@ -90,23 +94,23 @@ class AuthView(
val viewJob = viewModel.currentState.subscribeSafelyWithoutExceptions(uiScope) {
when (it) {
is InitAuthUIState -> {
is AuthUIState.Init -> {
disabled.value = false
errorText.value = when (it.showError) {
ServerUnavailableAuthUIError -> "Server unavailable"
AuthIncorrectAuthUIError -> {
ServerUnavailable -> "Server unavailable"
AuthIncorrect -> {
passwordState.value = ""
"Username or password is incorrect"
}
null -> null
}
}
LoadingAuthUIState -> {
AuthUIState.Loading -> {
disabled.value = true
errorText.value = null
}
AuthorizedAuthUIState -> {
AuthUIState.Authorized -> {
completion.complete(state.from)
}
}