NetNewsWire/Multiplatform/Shared/Add/Add Account Sheets/AddLocalAccountView.swift

141 lines
3.1 KiB
Swift
Raw Normal View History

2020-12-02 14:09:59 +01:00
//
2020-12-02 14:19:33 +01:00
// AddLocalAccountView.swift
2020-12-02 14:09:59 +01:00
// Multiplatform macOS
//
// Created by Stuart Breckenridge on 02/12/2020.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
import RSCore
2020-12-02 14:19:33 +01:00
struct AddLocalAccountView: View {
2020-12-02 14:09:59 +01:00
@State private var newAccountName: String = ""
2020-12-02 14:19:33 +01:00
@Environment (\.presentationMode) var presentationMode
2020-12-02 14:09:59 +01:00
2020-12-05 15:18:10 +01:00
var body: some View {
#if os(macOS)
macBody
#else
2020-12-07 12:22:35 +01:00
NavigationView {
iosBody
}
2020-12-05 15:18:10 +01:00
#endif
}
#if os(iOS)
var iosBody: some View {
List {
Section(header: formHeader, content: {
TextField("Account Name", text: $newAccountName)
})
2020-12-07 12:22:35 +01:00
Section(footer: formFooter, content: {
Button(action: {
let newAccount = AccountManager.shared.createAccount(type: .onMyMac)
newAccount.name = newAccountName
presentationMode.wrappedValue.dismiss()
}, label: {
HStack {
Spacer()
Text("Add Account")
Spacer()
}
})
2020-12-05 15:18:10 +01:00
})
2020-12-07 12:22:35 +01:00
}.navigationBarItems(leading:
2020-12-05 15:18:10 +01:00
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
2020-12-07 12:22:35 +01:00
Text("Cancel")
2020-12-05 15:18:10 +01:00
})
)
2020-12-07 12:22:35 +01:00
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(Text(AccountType.onMyMac.localizedAccountName()))
.listStyle(InsetGroupedListStyle())
2020-12-05 15:18:10 +01:00
}
#endif
#if os(macOS)
var macBody: some View {
2020-12-02 14:09:59 +01:00
VStack {
HStack(spacing: 16) {
VStack(alignment: .leading) {
AccountType.onMyMac.image()
.resizable()
.frame(width: 50, height: 50)
Spacer()
}
VStack(alignment: .leading, spacing: 8) {
Text("Create a local account on your Mac.")
.font(.headline)
Text("Local accounts store their data on your Mac. They do not sync across your devices.")
.font(.callout)
.foregroundColor(.secondary)
HStack {
Text("Name: ")
TextField("Account Name", text: $newAccountName)
}.padding(.top, 8)
Spacer()
HStack(spacing: 8) {
Spacer()
2020-12-02 14:19:33 +01:00
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
Text("Cancel")
.frame(width: 60)
2020-12-02 14:09:59 +01:00
}).keyboardShortcut(.cancelAction)
2020-12-05 15:18:10 +01:00
2020-12-02 14:19:33 +01:00
Button(action: {
let newAccount = AccountManager.shared.createAccount(type: .onMyMac)
newAccount.name = newAccountName
presentationMode.wrappedValue.dismiss()
}, label: {
Text("Create")
.frame(width: 60)
2020-12-02 14:09:59 +01:00
}).keyboardShortcut(.defaultAction)
}
}
}
}
.padding()
2020-12-05 14:09:34 +01:00
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
2020-12-02 14:46:00 +01:00
.textFieldStyle(RoundedBorderTextFieldStyle())
2020-12-05 15:18:10 +01:00
}
#endif
var formHeader: some View {
HStack {
2020-12-07 12:22:35 +01:00
Spacer()
2020-12-05 15:18:10 +01:00
VStack(alignment: .center) {
AccountType.onMyMac.image()
.resizable()
.frame(width: 50, height: 50)
}
2020-12-07 12:22:35 +01:00
Spacer()
}.padding(.vertical)
}
var formFooter: some View {
HStack {
Spacer()
VStack(spacing: 8) {
Text("Local accounts do not sync your feeds across devices.").foregroundColor(.secondary)
2020-12-07 12:22:35 +01:00
}
.multilineTextAlignment(.center)
.font(.caption)
Spacer()
}.padding(.vertical)
2020-12-05 15:18:10 +01:00
}
2020-12-02 14:09:59 +01:00
}
struct AddLocalAccount_Previews: PreviewProvider {
2020-12-05 15:18:10 +01:00
static var previews: some View {
AddLocalAccountView()
}
2020-12-02 14:09:59 +01:00
}