1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Shared/Settings/AccountsNavigationLink.swift
2022-10-27 18:03:57 +02:00

37 lines
943 B
Swift

import SwiftUI
struct AccountsNavigationLink: View {
@EnvironmentObject<AccountsModel> private var accounts
var instance: Instance
var body: some View {
NavigationLink(instance.longDescription) {
InstanceSettings(instance: instance)
}
.disabled(instance.app == .demoApp)
.buttonStyle(.plain)
.contextMenu {
removeInstanceButton(instance)
#if os(tvOS)
Button("Cancel", role: .cancel) {}
#endif
}
}
private func removeInstanceButton(_ instance: Instance) -> some View {
Button {
removeAction(instance)
} label: {
Label("Remove", systemImage: "trash")
}
}
private func removeAction(_ instance: Instance) {
if accounts.current?.instance == instance {
accounts.setCurrent(nil)
}
InstancesModel.remove(instance)
}
}