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 {
|
2019-09-08 03:50:57 +02:00
|
|
|
@Environment(\.presentationMode) var presentation
|
2019-06-12 15:33:14 +02:00
|
|
|
@State var name: String
|
2019-06-12 10:08:51 +02:00
|
|
|
|
2019-06-11 23:59:16 +02:00
|
|
|
var body: some View {
|
2019-09-12 03:50:03 +02:00
|
|
|
Form {
|
|
|
|
Section(header:
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
2019-09-12 17:19:06 +02:00
|
|
|
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: Account.defaultLocalAccountName)
|
|
|
|
.padding()
|
|
|
|
.layoutPriority(1.0)
|
2019-09-12 03:50:03 +02:00
|
|
|
Spacer()
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
2019-09-12 03:50:03 +02:00
|
|
|
) {
|
|
|
|
HStack {
|
|
|
|
TextField("Name", text: $name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
Button(action: { self.addAccount() }) {
|
|
|
|
Text("Add Account")
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
2019-09-12 03:50:03 +02:00
|
|
|
Spacer()
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-12 03:50:03 +02:00
|
|
|
.navigationBarTitle(Text(""), displayMode: .inline)
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
|
|
|
|
2019-06-12 10:08:51 +02:00
|
|
|
private func addAccount() {
|
2019-06-11 23:59:16 +02:00
|
|
|
let account = AccountManager.shared.createAccount(type: .onMyMac)
|
|
|
|
account.name = name
|
2019-06-12 10:08:51 +02:00
|
|
|
dismiss()
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
2019-06-12 10:08:51 +02:00
|
|
|
|
|
|
|
private func dismiss() {
|
2019-09-08 03:50:57 +02:00
|
|
|
presentation.wrappedValue.dismiss()
|
2019-06-12 10:08:51 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
struct SettingsLocalAccountView_Previews : PreviewProvider {
|
|
|
|
static var previews: some View {
|
2019-09-12 03:50:03 +02:00
|
|
|
SettingsLocalAccountView(name: "")
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|