NetNewsWire/Multiplatform/macOS/Preferences/Preference Panes/Accounts/AccountsPreferencesView.swift

92 lines
2.4 KiB
Swift
Raw Normal View History

2020-07-13 15:41:02 +02:00
//
// AccountsPreferencesView.swift
// macOS
//
// Created by Stuart Breckenridge on 27/6/20.
//
import SwiftUI
import Account
struct AccountsPreferencesView: View {
2020-07-13 17:10:50 +02:00
@StateObject var viewModel = AccountsPreferencesModel()
2020-07-13 15:41:02 +02:00
@State private var hoverOnAdd: Bool = false
@State private var hoverOnRemove: Bool = false
var body: some View {
VStack {
HStack(alignment: .top, spacing: 10) {
VStack(alignment: .leading) {
List(viewModel.sortedAccounts, id: \.accountID, selection: $viewModel.selectedConfiguredAccountID) {
ConfiguredAccountRow(account: $0)
.id($0.accountID)
}.overlay(
Group {
bottomButtonStack
}, alignment: .bottom)
}
2020-07-14 04:44:59 +02:00
.frame(width: 160, height: 300, alignment: .leading)
2020-07-13 15:41:02 +02:00
.border(Color.gray, width: 1)
2020-07-14 04:44:59 +02:00
EditAccountView(viewModel: viewModel)
.frame(height: 300, alignment: .leading)
2020-07-13 15:41:02 +02:00
}
Spacer()
}.sheet(isPresented: $viewModel.showAddAccountView,
onDismiss: { viewModel.showAddAccountView.toggle() },
content: {
AddAccountView(preferencesModel: viewModel)
})
}
var bottomButtonStack: some View {
VStack(alignment: .leading, spacing: 0) {
Divider()
HStack(alignment: .center, spacing: 4) {
Button(action: {
viewModel.showAddAccountView.toggle()
}, label: {
Image(systemName: "plus")
.font(.title)
.frame(width: 30, height: 30)
.overlay(RoundedRectangle(cornerRadius: 4, style: .continuous)
.foregroundColor(hoverOnAdd ? Color.gray.opacity(0.1) : Color.clear))
.padding(4)
})
.buttonStyle(BorderlessButtonStyle())
.onHover { hovering in
hoverOnAdd = hovering
}
.help("Add Account")
Button(action: {
if let account = viewModel.sortedAccounts.first(where: { $0.accountID == viewModel.selectedConfiguredAccountID }) {
AccountManager.shared.deleteAccount(account)
}
}, label: {
Image(systemName: "minus")
.font(.title)
.frame(width: 30, height: 30)
.overlay(RoundedRectangle(cornerRadius: 4, style: .continuous)
.foregroundColor(hoverOnRemove ? Color.gray.opacity(0.1) : Color.clear))
.padding(4)
})
.buttonStyle(BorderlessButtonStyle())
.onHover { hovering in
hoverOnRemove = hovering
}
.disabled(viewModel.selectedAccountIsDefault)
.help("Delete Account")
Spacer()
}
.background(Color.white)
}
}
}