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-09-08 17:18:45 +02:00
|
|
|
// 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 {
|
2019-06-18 23:54:51 +02:00
|
|
|
Form {
|
2019-06-11 23:59:16 +02:00
|
|
|
Section(header:
|
2019-09-08 11:09:05 +02:00
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: Account.defaultLocalAccountName).padding()
|
|
|
|
Spacer()
|
|
|
|
}
|
2019-06-11 23:59:16 +02:00
|
|
|
) {
|
|
|
|
HStack {
|
2019-09-08 03:50:57 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-08 17:18:45 +02:00
|
|
|
onDismiss()
|
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-08 17:18:45 +02:00
|
|
|
SettingsLocalAccountView(name: "", onDismiss: {})
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|