Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions Mactrix/Views/WelcomeSheetView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AuthenticationServices
import MatrixRustSDK
import SwiftUI
import OSLog

struct WelcomeSheetView: View {
@Environment(AppState.self) private var appState
Expand All @@ -17,7 +18,12 @@ struct WelcomeSheetView: View {
@State private var loading: Bool = false
@State private var showError: Error? = nil

private let defaultHomeserver = "matrix.org"

func loadHomeserver() {
if homeserverField.isEmpty {
homeserverField = defaultHomeserver
}
Task {
loading = true
defer { loading = false }
Expand Down Expand Up @@ -99,7 +105,8 @@ struct WelcomeSheetView: View {
.padding(.bottom)

Form {
TextField("Homeserver", text: $homeserverField, prompt: Text("matrix.org"))
TextField("Homeserver", text: $homeserverField, prompt:
Text(defaultHomeserver))
.disabled(loading)
.onSubmit { loadHomeserver() }

Expand All @@ -114,9 +121,23 @@ struct WelcomeSheetView: View {
.frame(maxWidth: 300)

if let showError = showError {
Text(showError.localizedDescription)
.foregroundStyle(Color.red)
.textSelection(.enabled)
let message: String = {
switch showError {
case let MatrixRustSDK.ClientBuildError
.InvalidServerName(message: msg):
return msg
case let MatrixRustSDK.ClientBuildError
.ServerUnreachable(message: msg):
return msg
default:
Logger.matrixClient.error("\(showError.localizedDescription)")
return "Something went wrong!"
Comment on lines +132 to +134
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this solution to make the errors prettier, since it default case catches too many errors under the unuseful "Something went wrong!" error. I'd rather have a harder to read error message than an opaque generic error like this.

For instance if you attempt to sign in and the username and password is incorrect this error is presented, the old error message was a bit harder to read, but it did say that the credentials were wrong.

Ideally, we should implement a nicely formatted error for all cases, but a simpler halfway solution is to return the original showError.localizedDescription if something goes wrong.

}
}()

Text(message)
.foregroundStyle(Color.red)
.textSelection(.enabled)
}
}
.padding()
Expand Down
Loading