This commit is contained in:
fmodf 2024-08-11 17:47:54 +02:00
parent 4ecd62ffe5
commit b72ff93ebe
2 changed files with 17 additions and 36 deletions

View file

@ -13,9 +13,6 @@ struct LoginScreen: View {
@FocusState private var focus: Field?
@State private var isLoading = false
@State private var isError = false
#if DEBUG
@State private var jidStr: String = "nartest1@conversations.im"
@State private var pass: String = "nartest12345"
@ -98,16 +95,6 @@ struct LoginScreen: View {
}
.padding(.horizontal, 32)
}
.if(isLoading) {
$0.loadingOverlay()
}
.alert(isPresented: $isError) {
Alert(
title: Text(L10n.Global.Error.title),
message: Text(L10n.Login.error),
dismissButton: .default(Text(L10n.Global.ok))
)
}
}
private var loginInputValid: Bool {
@ -115,7 +102,9 @@ struct LoginScreen: View {
}
private func tryLogin() async {
isLoading = true
router.showModal {
LoadingScreen()
}
// login with fake timeout
async let sleep: Void? = try? await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC)
@ -125,12 +114,17 @@ struct LoginScreen: View {
switch result {
case .success(let client):
clientsStore.addNewClient(client)
isLoading = false
isError = false
router.dismissModal()
case .failure:
isLoading = false
isError = true
router.dismissModal()
router.showAlert(
.alert,
title: L10n.Global.Error.title,
subtitle: L10n.Login.error
) {
Button(L10n.Global.ok, role: .cancel) {}
}
}
}
}

View file

@ -1,23 +1,10 @@
import Foundation
import SwiftUI
public extension View {
func loadingOverlay() -> some View {
modifier(LoadingOverlay())
}
}
struct LoadingOverlay: ViewModifier {
func body(content: Content) -> some View {
ZStack {
content
loadingView
}
}
private var loadingView: some View {
GeometryReader { proxyReader in
struct LoadingScreen: View {
var body: some View {
GeometryReader { geo in
ZStack {
// background with opacity
Color.Material.Elements.active.opacity(0.3)
.frame(maxWidth: .infinity, maxHeight: .infinity)
@ -26,7 +13,7 @@ struct LoadingOverlay: ViewModifier {
.progressViewStyle(
CircularProgressViewStyle(tint: .Material.Elements.active)
)
.position(x: proxyReader.size.width / 2, y: proxyReader.size.height / 2)
.position(x: geo.size.width / 2, y: geo.size.height / 2)
.controlSize(.large)
}
}