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