mirror of
https://github.com/yattee/yattee.git
synced 2025-04-28 07:50:33 +05:30
Encapsulate open channel action
This commit is contained in:
parent
a4c43d9a3a
commit
8d49934fe8
@ -41,6 +41,32 @@ final class NavigationModel: ObservableObject {
|
|||||||
@Published var presentingSettings = false
|
@Published var presentingSettings = false
|
||||||
@Published var presentingWelcomeScreen = false
|
@Published var presentingWelcomeScreen = false
|
||||||
|
|
||||||
|
static func openChannel(
|
||||||
|
_ channel: Channel,
|
||||||
|
player: PlayerModel,
|
||||||
|
recents: RecentsModel,
|
||||||
|
navigation: NavigationModel,
|
||||||
|
navigationStyle: NavigationStyle
|
||||||
|
) {
|
||||||
|
let recent = RecentItem(from: channel)
|
||||||
|
player.presentingPlayer = false
|
||||||
|
|
||||||
|
let openRecent = {
|
||||||
|
recents.add(recent)
|
||||||
|
navigation.presentingChannel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if navigationStyle == .tab {
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
|
openRecent()
|
||||||
|
}
|
||||||
|
} else if navigationStyle == .sidebar {
|
||||||
|
openRecent()
|
||||||
|
navigation.sidebarSectionChanged.toggle()
|
||||||
|
navigation.tabSelection = .recentlyOpened(recent.tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var tabSelectionBinding: Binding<TabSelection> {
|
var tabSelectionBinding: Binding<TabSelection> {
|
||||||
Binding<TabSelection>(
|
Binding<TabSelection>(
|
||||||
get: {
|
get: {
|
||||||
|
@ -8,18 +8,18 @@ struct ChannelCell: View {
|
|||||||
@Environment(\.navigationStyle) private var navigationStyle
|
@Environment(\.navigationStyle) private var navigationStyle
|
||||||
|
|
||||||
@EnvironmentObject<NavigationModel> private var navigation
|
@EnvironmentObject<NavigationModel> private var navigation
|
||||||
|
@EnvironmentObject<PlayerModel> private var player
|
||||||
@EnvironmentObject<RecentsModel> private var recents
|
@EnvironmentObject<RecentsModel> private var recents
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button {
|
Button {
|
||||||
let recent = RecentItem(from: channel)
|
NavigationModel.openChannel(
|
||||||
recents.add(recent)
|
channel,
|
||||||
navigation.presentingChannel = true
|
player: player,
|
||||||
|
recents: recents,
|
||||||
if navigationStyle == .sidebar {
|
navigation: navigation,
|
||||||
navigation.sidebarSectionChanged.toggle()
|
navigationStyle: navigationStyle
|
||||||
navigation.tabSelection = .recentlyOpened(recent.tag)
|
)
|
||||||
}
|
|
||||||
} label: {
|
} label: {
|
||||||
content
|
content
|
||||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||||
|
@ -97,14 +97,13 @@ struct VideoContextMenuView: View {
|
|||||||
|
|
||||||
private var openChannelButton: some View {
|
private var openChannelButton: some View {
|
||||||
Button {
|
Button {
|
||||||
let recent = RecentItem(from: video.channel)
|
NavigationModel.openChannel(
|
||||||
recents.add(recent)
|
video.channel,
|
||||||
navigation.presentingChannel = true
|
player: player,
|
||||||
|
recents: recents,
|
||||||
if navigationStyle == .sidebar {
|
navigation: navigation,
|
||||||
navigation.sidebarSectionChanged.toggle()
|
navigationStyle: navigationStyle
|
||||||
navigation.tabSelection = .recentlyOpened(recent.tag)
|
)
|
||||||
}
|
|
||||||
} label: {
|
} label: {
|
||||||
Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")
|
Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user