2021-07-07 22:39:18 +00:00
|
|
|
import Defaults
|
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
import URLImage
|
|
|
|
|
|
|
|
struct VideoDetailsView: View {
|
2021-07-11 20:52:49 +00:00
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
|
|
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
2021-07-07 22:39:18 +00:00
|
|
|
|
|
|
|
@ObservedObject private var store = Store<Video>()
|
|
|
|
|
|
|
|
var resource: Resource {
|
2021-07-11 20:52:49 +00:00
|
|
|
InvidiousAPI.shared.video(video.id)
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
var video: Video
|
|
|
|
|
|
|
|
init(_ video: Video) {
|
|
|
|
self.video = video
|
2021-07-07 22:39:18 +00:00
|
|
|
resource.addObserver(store)
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
2021-07-11 20:52:49 +00:00
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
VStack {
|
|
|
|
Spacer()
|
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
|
|
if let video = store.item {
|
|
|
|
VStack(alignment: .center) {
|
|
|
|
ZStack(alignment: .bottom) {
|
|
|
|
Group {
|
2021-07-12 17:05:16 +00:00
|
|
|
if let thumbnail = video.thumbnailURL(quality: .maxres) {
|
2021-07-11 20:52:49 +00:00
|
|
|
// to replace with AsyncImage when it is fixed with lazy views
|
|
|
|
URLImage(thumbnail) { image in
|
|
|
|
image
|
|
|
|
.resizable()
|
|
|
|
.aspectRatio(contentMode: .fill)
|
|
|
|
.frame(width: 1600, height: 800)
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
.frame(width: 1600, height: 800)
|
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(video.title)
|
|
|
|
.font(.system(size: 40))
|
2021-07-07 22:39:18 +00:00
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
HStack {
|
|
|
|
NavigationLink(destination: PlayerView(id: video.id)) {
|
|
|
|
HStack(spacing: 8) {
|
|
|
|
Image(systemName: "play.rectangle.fill")
|
2021-07-07 22:39:18 +00:00
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
Text("Play")
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 22:39:18 +00:00
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
openChannelButton
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
.padding(40)
|
|
|
|
.frame(width: 1600, alignment: .leading)
|
|
|
|
.background(.thinMaterial)
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
.mask(RoundedRectangle(cornerRadius: 20))
|
|
|
|
VStack {
|
|
|
|
Text(video.description)
|
|
|
|
.lineLimit(nil)
|
|
|
|
.focusable()
|
|
|
|
}.frame(width: 1600, alignment: .leading)
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
Spacer()
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
Spacer()
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
.background(.thinMaterial)
|
|
|
|
|
2021-07-07 22:39:18 +00:00
|
|
|
.onAppear {
|
|
|
|
resource.loadIfNeeded()
|
|
|
|
}
|
|
|
|
.edgesIgnoringSafeArea(.all)
|
|
|
|
}
|
|
|
|
|
|
|
|
var openChannelButton: some View {
|
|
|
|
let channel = Channel.from(video: store.item!)
|
|
|
|
|
|
|
|
return Button("Open \(channel.name) channel") {
|
2021-07-11 20:52:49 +00:00
|
|
|
navigationState.openChannel(channel)
|
|
|
|
dismiss()
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|