2022-12-14 11:56:47 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChannelLinkView<ChannelLabel: View>: View {
|
|
|
|
let channel: Channel
|
|
|
|
let channelLabel: ChannelLabel
|
|
|
|
|
|
|
|
@Environment(\.inChannelView) private var inChannelView
|
2022-12-14 17:10:50 +00:00
|
|
|
@Environment(\.inNavigationView) private var inNavigationView
|
2022-12-14 11:56:47 +00:00
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
|
|
|
|
|
|
init(
|
|
|
|
channel: Channel,
|
|
|
|
@ViewBuilder channelLabel: () -> ChannelLabel
|
|
|
|
) {
|
|
|
|
self.channel = channel
|
|
|
|
self.channelLabel = channelLabel()
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
channelControl
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private var channelControl: some View {
|
|
|
|
if !channel.name.isEmpty {
|
|
|
|
#if os(tvOS)
|
|
|
|
channelLabel
|
|
|
|
#else
|
2022-12-14 17:10:50 +00:00
|
|
|
if navigationStyle == .tab, inNavigationView {
|
2022-12-14 11:56:47 +00:00
|
|
|
channelNavigationLink
|
|
|
|
} else {
|
|
|
|
channelButton
|
|
|
|
#if os(macOS)
|
|
|
|
.onHover(perform: onHover(_:))
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private var channelNavigationLink: some View {
|
|
|
|
NavigationLink(destination: ChannelVideosView(channel: channel)) {
|
|
|
|
channelLabel
|
2022-12-17 18:35:07 +00:00
|
|
|
.lineLimit(1)
|
2022-12-14 11:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private var channelButton: some View {
|
|
|
|
Button {
|
|
|
|
guard !inChannelView else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationModel.shared.openChannel(
|
|
|
|
channel,
|
|
|
|
navigationStyle: navigationStyle
|
|
|
|
)
|
|
|
|
} label: {
|
|
|
|
channelLabel
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.buttonStyle(.card)
|
|
|
|
#else
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
#endif
|
|
|
|
.help("\(channel.name) Channel")
|
|
|
|
}
|
|
|
|
|
|
|
|
#if os(macOS)
|
|
|
|
private func onHover(_ inside: Bool) {
|
|
|
|
if inside {
|
|
|
|
NSCursor.pointingHand.push()
|
|
|
|
} else {
|
|
|
|
NSCursor.pop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|