NetNewsWire/iOS/Settings/Account/SettingsLocalAccountView.swift

68 lines
1.4 KiB
Swift
Raw Normal View History

2019-06-11 23:59:16 +02:00
//
// SettingsLocalAccountView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 6/11/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
struct SettingsLocalAccountView : View {
@Environment(\.presentationMode) var presentation
2019-06-12 15:33:14 +02:00
@State var name: String
// This is a hack around the fact that onDismiss isn't being called by the sheet modifier.
var onDismiss: () -> Void
2019-06-11 23:59:16 +02:00
var body: some View {
NavigationView {
Form {
2019-06-11 23:59:16 +02:00
Section(header:
HStack {
Spacer()
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: Account.defaultLocalAccountName).padding()
Spacer()
}
2019-06-11 23:59:16 +02:00
) {
HStack {
TextField("Name", text: $name)
2019-06-11 23:59:16 +02:00
}
}
Section {
HStack {
Spacer()
Button(action: { self.addAccount() }) {
Text("Add Account")
}
Spacer()
}
}
}
.navigationBarTitle(Text(""), displayMode: .inline)
2019-06-12 15:33:14 +02:00
.navigationBarItems(leading: Button(action: { self.dismiss() }) { Text("Cancel") } )
2019-06-11 23:59:16 +02:00
}
}
private func addAccount() {
2019-06-11 23:59:16 +02:00
let account = AccountManager.shared.createAccount(type: .onMyMac)
account.name = name
dismiss()
2019-06-11 23:59:16 +02:00
}
private func dismiss() {
presentation.wrappedValue.dismiss()
onDismiss()
}
2019-06-11 23:59:16 +02:00
}
#if DEBUG
struct SettingsLocalAccountView_Previews : PreviewProvider {
static var previews: some View {
SettingsLocalAccountView(name: "", onDismiss: {})
2019-06-11 23:59:16 +02:00
}
}
#endif