mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-06 04:52:24 +00:00
Improve add account screen
This commit is contained in:
parent
691b3f2667
commit
b577e41eae
1 changed files with 28 additions and 9 deletions
|
@ -44,8 +44,10 @@ struct AddAccountView: View {
|
||||||
if let instanceFetchError {
|
if let instanceFetchError {
|
||||||
Text(instanceFetchError)
|
Text(instanceFetchError)
|
||||||
}
|
}
|
||||||
if let instance {
|
if instance != nil || !instanceName.isEmpty {
|
||||||
signInSection
|
signInSection
|
||||||
|
}
|
||||||
|
if let instance {
|
||||||
InstanceInfoSection(instance: instance)
|
InstanceInfoSection(instance: instance)
|
||||||
} else {
|
} else {
|
||||||
instancesListView
|
instancesListView
|
||||||
|
@ -68,7 +70,10 @@ struct AddAccountView: View {
|
||||||
isInstanceURLFieldFocused = true
|
isInstanceURLFieldFocused = true
|
||||||
let client = InstanceSocialClient()
|
let client = InstanceSocialClient()
|
||||||
Task {
|
Task {
|
||||||
self.instances = await client.fetchInstances()
|
let instances = await client.fetchInstances()
|
||||||
|
withAnimation {
|
||||||
|
self.instances = instances
|
||||||
|
}
|
||||||
}
|
}
|
||||||
isSigninIn = false
|
isSigninIn = false
|
||||||
}
|
}
|
||||||
|
@ -76,16 +81,22 @@ struct AddAccountView: View {
|
||||||
instanceNamePublisher.send(newValue)
|
instanceNamePublisher.send(newValue)
|
||||||
}
|
}
|
||||||
.onReceive(instanceNamePublisher.debounce(for: .milliseconds(500), scheduler: DispatchQueue.main)) { newValue in
|
.onReceive(instanceNamePublisher.debounce(for: .milliseconds(500), scheduler: DispatchQueue.main)) { newValue in
|
||||||
|
let newValue = newValue
|
||||||
|
.replacingOccurrences(of: "http://", with: "")
|
||||||
|
.replacingOccurrences(of: "https://", with: "")
|
||||||
let client = Client(server: newValue)
|
let client = Client(server: newValue)
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
self.instance = try await client.get(endpoint: Instances.instance)
|
let instance: Instance = try await client.get(endpoint: Instances.instance)
|
||||||
self.instanceFetchError = nil
|
withAnimation {
|
||||||
|
self.instance = instance
|
||||||
|
}
|
||||||
|
instanceFetchError = nil
|
||||||
} catch _ as DecodingError {
|
} catch _ as DecodingError {
|
||||||
self.instance = nil
|
instance = nil
|
||||||
self.instanceFetchError = "account.add.error.instance-not-supported"
|
instanceFetchError = "account.add.error.instance-not-supported"
|
||||||
} catch {
|
} catch {
|
||||||
self.instance = nil
|
instance = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,6 +113,11 @@ struct AddAccountView: View {
|
||||||
await continueSignIn(url: url)
|
await continueSignIn(url: url)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.onChange(of: oauthURL, perform: { newValue in
|
||||||
|
if newValue == nil {
|
||||||
|
isSigninIn = false
|
||||||
|
}
|
||||||
|
})
|
||||||
.sheet(item: $oauthURL, content: { url in
|
.sheet(item: $oauthURL, content: { url in
|
||||||
SafariView(url: url)
|
SafariView(url: url)
|
||||||
})
|
})
|
||||||
|
@ -111,15 +127,18 @@ struct AddAccountView: View {
|
||||||
private var signInSection: some View {
|
private var signInSection: some View {
|
||||||
Section {
|
Section {
|
||||||
Button {
|
Button {
|
||||||
isSigninIn = true
|
withAnimation {
|
||||||
|
isSigninIn = true
|
||||||
|
}
|
||||||
Task {
|
Task {
|
||||||
await signIn()
|
await signIn()
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
if isSigninIn {
|
if isSigninIn || !instanceName.isEmpty && instance == nil {
|
||||||
ProgressView()
|
ProgressView()
|
||||||
|
.id(instanceName)
|
||||||
.tint(theme.labelColor)
|
.tint(theme.labelColor)
|
||||||
} else {
|
} else {
|
||||||
Text("account.add.sign-in")
|
Text("account.add.sign-in")
|
||||||
|
|
Loading…
Reference in a new issue