yattee/Shared/Settings/AccountsNavigationLink.swift

36 lines
899 B
Swift
Raw Normal View History

2021-11-28 14:37:55 +00:00
import SwiftUI
struct AccountsNavigationLink: View {
@EnvironmentObject<AccountsModel> private var accounts
var instance: Instance
var body: some View {
NavigationLink(instance.longDescription) {
InstanceSettings(instance: instance)
2021-11-28 14:37:55 +00:00
}
.buttonStyle(.plain)
.contextMenu {
removeInstanceButton(instance)
#if os(tvOS)
Button("Cancel", role: .cancel) {}
#endif
2021-11-28 14:37:55 +00:00
}
}
private func removeInstanceButton(_ instance: Instance) -> some View {
2022-01-06 15:02:53 +00:00
Button {
removeAction(instance)
} label: {
Label("Remove", systemImage: "trash")
2021-11-28 14:37:55 +00:00
}
}
private func removeAction(_ instance: Instance) {
if accounts.current?.instance == instance {
accounts.setCurrent(nil)
}
InstancesModel.remove(instance)
}
}