Fix profile name reset to initial on error
This commit is contained in:
parent
ed16617288
commit
ab7e6359ae
|
@ -95,10 +95,11 @@ struct AddHostView: View {
|
|||
private var processingView: some View {
|
||||
AddProfileView.ProfileNameSection(
|
||||
profileName: $viewModel.profileName,
|
||||
initialName: url.normalizedFilename,
|
||||
errorMessage: viewModel.errorMessage
|
||||
) {
|
||||
processProfile(replacingExisting: false)
|
||||
}.onAppear {
|
||||
viewModel.presetName(withURL: url)
|
||||
}
|
||||
if viewModel.requiresPassphrase {
|
||||
encryptionSection
|
||||
|
|
|
@ -30,6 +30,8 @@ import TunnelKitWireGuard
|
|||
|
||||
extension AddHostView {
|
||||
struct ViewModel {
|
||||
private var isNamePreset = false
|
||||
|
||||
var profileName = ""
|
||||
|
||||
private(set) var requiresPassphrase = false
|
||||
|
@ -41,6 +43,14 @@ extension AddHostView {
|
|||
private(set) var errorMessage: String?
|
||||
|
||||
var isAskingOverwrite = false
|
||||
|
||||
mutating func presetName(withURL url: URL) {
|
||||
guard !isNamePreset else {
|
||||
return
|
||||
}
|
||||
isNamePreset = true
|
||||
profileName = url.normalizedFilename
|
||||
}
|
||||
|
||||
@MainActor
|
||||
mutating func processURL(
|
||||
|
|
|
@ -34,8 +34,6 @@ enum AddProfileView {
|
|||
struct ProfileNameSection: View {
|
||||
@Binding var profileName: String
|
||||
|
||||
let initialName: String
|
||||
|
||||
let errorMessage: String?
|
||||
|
||||
let onCommit: () -> Void
|
||||
|
@ -46,12 +44,6 @@ enum AddProfileView {
|
|||
footer: themeErrorMessage(errorMessage)
|
||||
) {
|
||||
TextField(L10n.Global.Placeholders.profileName, text: $profileName, onCommit: onCommit)
|
||||
.onAppear {
|
||||
// XXX: this is reset on the way back, but:
|
||||
// host: there is no back button after processing profile
|
||||
// host/provider: back button is hidden after going to credentials
|
||||
profileName = initialName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,10 +56,11 @@ extension AddProviderView {
|
|||
List {
|
||||
AddProfileView.ProfileNameSection(
|
||||
profileName: $viewModel.profileName,
|
||||
initialName: providerMetadata.fullName,
|
||||
errorMessage: viewModel.errorMessage
|
||||
) {
|
||||
saveProfile(replacingExisting: false)
|
||||
}.onAppear {
|
||||
viewModel.presetName(withMetadata: providerMetadata)
|
||||
}
|
||||
let headers = profileManager.headers.sorted()
|
||||
if !headers.isEmpty {
|
||||
|
|
|
@ -124,11 +124,21 @@ extension AddProviderView {
|
|||
|
||||
extension AddProviderView.NameView {
|
||||
struct ViewModel {
|
||||
private var isNamePreset = false
|
||||
|
||||
var profileName = ""
|
||||
|
||||
var isAskingOverwrite = false
|
||||
|
||||
private(set) var errorMessage: String?
|
||||
|
||||
mutating func presetName(withMetadata metadata: ProviderMetadata) {
|
||||
guard !isNamePreset else {
|
||||
return
|
||||
}
|
||||
isNamePreset = true
|
||||
profileName = metadata.fullName
|
||||
}
|
||||
|
||||
@MainActor
|
||||
mutating func addProfile(
|
||||
|
|
Loading…
Reference in New Issue