mirror of
https://github.com/yattee/yattee.git
synced 2025-10-25 08:48:17 +00:00
Minor fixes, extract video context menu view
This commit is contained in:
29
Apple TV/VideoContextMenuView.swift
Normal file
29
Apple TV/VideoContextMenuView.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideoContextMenuView: View {
|
||||
@Default(.tabSelection) var tabSelection
|
||||
|
||||
let video: Video
|
||||
|
||||
var body: some View {
|
||||
if tabSelection == .channel {
|
||||
closeChannelButton(from: video)
|
||||
} else {
|
||||
openChannelButton(from: video)
|
||||
}
|
||||
}
|
||||
|
||||
func openChannelButton(from video: Video) -> some View {
|
||||
Button("\(video.author) Channel") {
|
||||
Defaults[.openChannel] = Channel.from(video: video)
|
||||
tabSelection = .channel
|
||||
}
|
||||
}
|
||||
|
||||
func closeChannelButton(from video: Video) -> some View {
|
||||
Button("Close \(Channel.from(video: video).name) Channel") {
|
||||
Defaults.reset(.openChannel)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosCellsView: View {
|
||||
@Default(.tabSelection) var tabSelection
|
||||
|
||||
@State private var columns: Int
|
||||
|
||||
init(videos: [Video], columns: Int = 3) {
|
||||
@@ -15,6 +18,7 @@ struct VideosCellsView: View {
|
||||
LazyVGrid(columns: items, spacing: 10) {
|
||||
ForEach(videos) { video in
|
||||
VideoCellView(video: video)
|
||||
.contextMenu { VideoContextMenuView(video: video) }
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
||||
@@ -2,8 +2,6 @@ import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosListView: View {
|
||||
@Default(.tabSelection) var tabSelection
|
||||
|
||||
var videos: [Video]
|
||||
|
||||
var body: some View {
|
||||
@@ -11,13 +9,7 @@ struct VideosListView: View {
|
||||
List {
|
||||
ForEach(videos) { video in
|
||||
VideoListRowView(video: video)
|
||||
.contextMenu {
|
||||
if tabSelection == .channel {
|
||||
closeChannelButton(name: video.author)
|
||||
} else {
|
||||
openChannelButton(from: video)
|
||||
}
|
||||
}
|
||||
.contextMenu { VideoContextMenuView(video: video) }
|
||||
.listRowInsets(listRowInsets)
|
||||
}
|
||||
}
|
||||
@@ -25,19 +17,6 @@ struct VideosListView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func openChannelButton(from video: Video) -> some View {
|
||||
Button("\(video.author) Channel") {
|
||||
Defaults[.openChannel] = Channel.from(video: video)
|
||||
tabSelection = .channel
|
||||
}
|
||||
}
|
||||
|
||||
func closeChannelButton(name: String) -> some View {
|
||||
Button("Close \(name) Channel") {
|
||||
Defaults.reset(.openChannel)
|
||||
}
|
||||
}
|
||||
|
||||
var listRowInsets: EdgeInsets {
|
||||
EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosView: View {
|
||||
@EnvironmentObject private var profile: Profile
|
||||
@State private var profile = Profile()
|
||||
|
||||
var videos: [Video]
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct ViewOptionsView: View {
|
||||
@EnvironmentObject private var profile: Profile
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Default(.layout) var layout
|
||||
|
||||
|
||||
Reference in New Issue
Block a user