Handle 'invalid server' error in server selection screen properly. (#214)

* Handle 'invalid server' error in server selection screen properly.

* Use `action_learn_more` for composing the server location footer action.
This commit is contained in:
Jorge Martin Espinosa 2023-03-21 09:34:14 +01:00 committed by GitHub
parent 93a77d94c1
commit 2906168baa
24 changed files with 132 additions and 127 deletions

View file

@ -36,13 +36,13 @@ sealed interface Async<out T> {
}
}
suspend fun <T> (suspend () -> T).execute(state: MutableState<Async<T>>) {
suspend fun <T> (suspend () -> T).execute(state: MutableState<Async<T>>, errorMapping: ((Throwable) -> Throwable)? = null) {
try {
state.value = Async.Loading()
val result = this()
state.value = Async.Success(result)
} catch (error: Throwable) {
state.value = Async.Failure(error)
state.value = Async.Failure(errorMapping?.invoke(error) ?: error)
}
}

View file

@ -18,7 +18,6 @@ package io.element.android.libraries.designsystem.components.dialogs
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.AlertDialogDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@ -36,8 +35,8 @@ import io.element.android.libraries.ui.strings.R as StringR
fun ErrorDialog(
content: String,
modifier: Modifier = Modifier,
title: String = stringResource(id = StringR.string.dialog_title_error),
submitText: String = stringResource(id = StringR.string.ok),
title: String = ErrorDialogDefaults.title,
submitText: String = ErrorDialogDefaults.submitText,
onDismiss: () -> Unit = {},
shape: Shape = AlertDialogDefaults.shape,
containerColor: Color = AlertDialogDefaults.containerColor,
@ -69,6 +68,11 @@ fun ErrorDialog(
)
}
object ErrorDialogDefaults {
val title: String @Composable get() = stringResource(id = StringR.string.dialog_title_error)
val submitText: String @Composable get() = stringResource(id = StringR.string.ok)
}
@Preview
@Composable
internal fun ErrorDialogLightPreview() = ElementPreviewLight { ContentToPreview() }

View file

@ -12,12 +12,13 @@
<string name="login_hide_password">Hide password</string>
<string name="ex_choose_server_subtitle">What is the address of your server?</string>
<string name="server_selection_server_footer">You can only connect to an existing server that supports sliding sync. Your homeserver admin will need to configure it.</string>
<string name="server_selection_server_footer_action">Learn more</string>
<string name="server_selection_sliding_sync_alert_title">Server not supported</string>
<string name="server_selection_sliding_sync_alert_message">This server currently doesn\'t support sliding sync.</string>
<string name="server_selection_invalid_homeserver_error">We couldn\'t reach this homeserver. Please check that you have entered the homeserver URL correctly. If the URL is correct, contact your homeserver administrator for further help.</string>
<!-- Create room -->
<string name="search_for_someone">Search for someone</string>
<string name="new_room">New room</string>
<!-- Room list -->
<string name="notice_room_invite_accepted_by_you">You accepted the invite</string>
<string name="notice_room_invite_accepted">%1$s accepted the invite</string>
@ -58,5 +59,4 @@
<string name="session_verification_start">Continue</string>
<string name="verification_conclusion_ok_self_notice_title">Verification complete</string>
</resources>