More fixes
This commit is contained in:
parent
05e3256da4
commit
fa9b873ba6
5 changed files with 23 additions and 24 deletions
|
|
@ -192,6 +192,7 @@ class LoginFlowNode @AssistedInject constructor(
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
onDispose {
|
onDispose {
|
||||||
activity = null
|
activity = null
|
||||||
|
accountProviderDataSource.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Children(
|
Children(
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,11 @@ import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import io.element.android.features.login.impl.error.ChangeServerError
|
|
||||||
import io.element.android.features.login.impl.datasource.AccountProviderDataSource
|
import io.element.android.features.login.impl.datasource.AccountProviderDataSource
|
||||||
import io.element.android.features.login.impl.util.LoginConstants
|
import io.element.android.features.login.impl.error.ChangeServerError
|
||||||
import io.element.android.libraries.architecture.Async
|
import io.element.android.libraries.architecture.Async
|
||||||
import io.element.android.libraries.architecture.Presenter
|
import io.element.android.libraries.architecture.Presenter
|
||||||
import io.element.android.libraries.architecture.execute
|
import io.element.android.libraries.architecture.execute
|
||||||
|
|
@ -57,12 +55,8 @@ class AccountProviderPresenter @AssistedInject constructor(
|
||||||
@Composable
|
@Composable
|
||||||
override fun present(): AccountProviderState {
|
override fun present(): AccountProviderState {
|
||||||
val accountProvider by accountProviderDataSource.flow().collectAsState()
|
val accountProvider by accountProviderDataSource.flow().collectAsState()
|
||||||
val currentHomeServerDetails = authenticationService.getHomeserverDetails().collectAsState().value
|
|
||||||
val localCoroutineScope = rememberCoroutineScope()
|
val localCoroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
val homeserver = rememberSaveable {
|
|
||||||
mutableStateOf(currentHomeServerDetails?.url ?: LoginConstants.DEFAULT_HOMESERVER_URL)
|
|
||||||
}
|
|
||||||
val loginFlowAction: MutableState<Async<LoginFlow>> = remember {
|
val loginFlowAction: MutableState<Async<LoginFlow>> = remember {
|
||||||
mutableStateOf(Async.Uninitialized)
|
mutableStateOf(Async.Uninitialized)
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +64,7 @@ class AccountProviderPresenter @AssistedInject constructor(
|
||||||
fun handleEvents(event: AccountProviderEvents) {
|
fun handleEvents(event: AccountProviderEvents) {
|
||||||
when (event) {
|
when (event) {
|
||||||
AccountProviderEvents.Continue -> {
|
AccountProviderEvents.Continue -> {
|
||||||
localCoroutineScope.submit(homeserver, loginFlowAction)
|
localCoroutineScope.submit(accountProvider.title, loginFlowAction)
|
||||||
}
|
}
|
||||||
AccountProviderEvents.ClearError -> loginFlowAction.value = Async.Uninitialized
|
AccountProviderEvents.ClearError -> loginFlowAction.value = Async.Uninitialized
|
||||||
}
|
}
|
||||||
|
|
@ -85,12 +79,11 @@ class AccountProviderPresenter @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CoroutineScope.submit(
|
private fun CoroutineScope.submit(
|
||||||
homeserverUrl: MutableState<String>,
|
homeserverUrl: String,
|
||||||
loginFlowAction: MutableState<Async<LoginFlow>>,
|
loginFlowAction: MutableState<Async<LoginFlow>>,
|
||||||
) = launch {
|
) = launch {
|
||||||
suspend {
|
suspend {
|
||||||
val domain = tryOrNull { URL(homeserverUrl.value) }?.host ?: homeserverUrl.value
|
val domain = tryOrNull { URL(homeserverUrl) }?.host ?: homeserverUrl
|
||||||
homeserverUrl.value = domain
|
|
||||||
authenticationService.setHomeserver(domain).map {
|
authenticationService.setHomeserver(domain).map {
|
||||||
authenticationService.getHomeserverDetails().value!!
|
authenticationService.getHomeserverDetails().value!!
|
||||||
}.map {
|
}.map {
|
||||||
|
|
|
||||||
|
|
@ -114,14 +114,7 @@ fun AccountProviderView(
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
when (state.loginFlow) {
|
when (state.loginFlow) {
|
||||||
is Async.Failure -> {
|
is Async.Failure -> Unit // Error dialog will be displayed
|
||||||
AsyncFailure(
|
|
||||||
throwable = state.loginFlow.error,
|
|
||||||
onRetry = {
|
|
||||||
state.eventSink.invoke(AccountProviderEvents.Continue)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
is Async.Loading -> Unit // The Continue button shows the loading state
|
is Async.Loading -> Unit // The Continue button shows the loading state
|
||||||
is Async.Success -> {
|
is Async.Success -> {
|
||||||
when (val loginFlowState = state.loginFlow.state) {
|
when (val loginFlowState = state.loginFlow.state) {
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import io.element.android.libraries.architecture.Async
|
import io.element.android.libraries.architecture.Async
|
||||||
import io.element.android.libraries.architecture.Presenter
|
import io.element.android.libraries.architecture.Presenter
|
||||||
import io.element.android.libraries.architecture.execute
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
@ -63,9 +63,17 @@ class ChangeAccountProviderFormPresenter @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CoroutineScope.userInput(userInput: String, userInputResult: MutableState<Async<List<HomeserverData>>>) = launch {
|
// Could be reworked using LaunchedEffect
|
||||||
suspend {
|
private fun CoroutineScope.userInput(userInput: String, state: MutableState<Async<List<HomeserverData>>>) = launch {
|
||||||
homeserverResolver.resolve(userInput)
|
state.value = Async.Uninitialized
|
||||||
}.execute(userInputResult)
|
// Debounce
|
||||||
|
delay(300)
|
||||||
|
state.value = Async.Loading()
|
||||||
|
try {
|
||||||
|
val result = homeserverResolver.resolve(userInput)
|
||||||
|
state.value = Async.Success(result)
|
||||||
|
} catch (error: Throwable) {
|
||||||
|
state.value = Async.Failure(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ class AccountProviderDataSource @Inject constructor(
|
||||||
return accountProvider.asStateFlow()
|
return accountProvider.asStateFlow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun reset() {
|
||||||
|
accountProvider.tryEmit(defaultAccountProvider)
|
||||||
|
}
|
||||||
|
|
||||||
fun userSelection(data: AccountProvider) {
|
fun userSelection(data: AccountProvider) {
|
||||||
accountProvider.tryEmit(data)
|
accountProvider.tryEmit(data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue