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 {
|
|
|
|
@State var name: String
|
2019-06-12 10:08:51 +02:00
|
|
|
@Environment(\.isPresented) private var isPresented
|
|
|
|
|
2019-06-11 23:59:16 +02:00
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
|
|
|
List {
|
|
|
|
Section(header:
|
|
|
|
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: "On My Device").padding()
|
|
|
|
) {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
TextField($name, placeholder: Text("Name (Optional)"))
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
Button(action: { self.addAccount() }) {
|
|
|
|
Text("Add Account")
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.listStyle(.grouped)
|
|
|
|
.navigationBarTitle(Text(""), displayMode: .inline)
|
2019-06-12 10:08:51 +02:00
|
|
|
.navigationBarItems(trailing: Button(action: { self.dismiss() }) { Text("Cancel") } )
|
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() {
|
|
|
|
isPresented?.value = false
|
|
|
|
}
|
|
|
|
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
struct SettingsLocalAccountView_Previews : PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
SettingsLocalAccountView(name: "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|