1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Settings/AccountsNavigationLink.swift

36 lines
911 B
Swift
Raw Normal View History

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