Minor fixes, extract video context menu view

This commit is contained in:
Arkadiusz Fal
2021-06-28 17:27:53 +02:00
parent f7d0e2131c
commit 6d35394ffd
11 changed files with 54 additions and 40 deletions

View 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)
}
}
}

View File

@@ -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()

View File

@@ -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)
}

View File

@@ -2,7 +2,7 @@ import Defaults
import SwiftUI
struct VideosView: View {
@EnvironmentObject private var profile: Profile
@State private var profile = Profile()
var videos: [Video]

View File

@@ -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