mirror of
https://github.com/yattee/yattee.git
synced 2025-10-28 19:21:58 +00:00
Channel view
This commit is contained in:
52
Apple TV/ChannelView.swift
Normal file
52
Apple TV/ChannelView.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ChannelView: View {
|
||||
@ObservedObject private var provider = ChannelVideosProvider()
|
||||
@ObservedObject var state: AppState
|
||||
|
||||
@Binding var tabSelection: TabSelection
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
List {
|
||||
ForEach(videos) { video in
|
||||
VideoThumbnailView(video: video)
|
||||
.contextMenu {
|
||||
Button("Close \(video.author) channel", action: {
|
||||
state.closeChannel()
|
||||
tabSelection = .popular
|
||||
})
|
||||
}
|
||||
.listRowInsets(listRowInsets)
|
||||
}
|
||||
}
|
||||
.listStyle(GroupedListStyle())
|
||||
}
|
||||
.task {
|
||||
async {
|
||||
provider.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var listRowInsets: EdgeInsets {
|
||||
EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30)
|
||||
}
|
||||
|
||||
var videos: [Video] {
|
||||
if state.channelID != provider.channelID {
|
||||
provider.videos = []
|
||||
provider.channelID = state.channelID
|
||||
provider.load()
|
||||
}
|
||||
|
||||
return provider.videos
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// struct ChannelView_Previews: PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// ChannelView()
|
||||
// }
|
||||
// }
|
||||
@@ -1,14 +1,21 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct PopularVideosView: View {
|
||||
@ObservedObject private var popular = PopluarVideosProvider()
|
||||
@ObservedObject private var provider = PopularVideosProvider()
|
||||
@ObservedObject var state: AppState
|
||||
@Binding var tabSelection: TabSelection
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
List {
|
||||
ForEach(popular.videos) { video in
|
||||
ForEach(provider.videos) { video in
|
||||
VideoThumbnailView(video: video)
|
||||
.contextMenu {
|
||||
Button("\(video.author) Channel", action: {
|
||||
state.setChannel(from: video)
|
||||
tabSelection = .channel
|
||||
})
|
||||
}
|
||||
.listRowInsets(listRowInsets)
|
||||
}
|
||||
}
|
||||
@@ -16,11 +23,11 @@ struct PopularVideosView: View {
|
||||
}
|
||||
.task {
|
||||
async {
|
||||
popular.load()
|
||||
provider.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var listRowInsets: EdgeInsets {
|
||||
EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SearchView: View {
|
||||
@State var query = ""
|
||||
@ObservedObject private var provider = SearchedVideosProvider()
|
||||
|
||||
|
||||
@State var query = ""
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
SearchedVideosView(provider: provider, query: $query)
|
||||
.searchable(text: $query)
|
||||
}
|
||||
SearchedVideosView(provider: provider, query: $query)
|
||||
.searchable(text: $query)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SearchedVideosView: View {
|
||||
@ObservedObject var provider: SearchedVideosProvider
|
||||
@ObservedObject var provider = SearchedVideosProvider()
|
||||
|
||||
@Binding var query: String
|
||||
|
||||
@Environment(\.isSearching) var isSearching
|
||||
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
List {
|
||||
@@ -21,27 +20,28 @@ struct SearchedVideosView: View {
|
||||
var listRowInsets: EdgeInsets {
|
||||
EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30)
|
||||
}
|
||||
|
||||
|
||||
var videos: [Video] {
|
||||
var newQuery = query
|
||||
|
||||
|
||||
if let url = URLComponents(string: query),
|
||||
let queryItem = url.queryItems?.first(where: { item in item.name == "v" }),
|
||||
let id = queryItem.value {
|
||||
let id = queryItem.value
|
||||
{
|
||||
newQuery = id
|
||||
}
|
||||
|
||||
if (newQuery != provider.query) {
|
||||
|
||||
if newQuery != provider.query {
|
||||
provider.query = newQuery
|
||||
provider.load()
|
||||
}
|
||||
|
||||
|
||||
return provider.videos
|
||||
}
|
||||
}
|
||||
|
||||
//struct SearchedVideosView_Previews: PreviewProvider {
|
||||
// struct SearchedVideosView_Previews: PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// SearchedVideosView()
|
||||
// }
|
||||
//}
|
||||
// }
|
||||
|
||||
@@ -10,14 +10,21 @@ struct VideoThumbnailView: View {
|
||||
var body: some View {
|
||||
NavigationLink(destination: PlayerView(id: video.id)) {
|
||||
HStack(alignment: .top, spacing: 2) {
|
||||
// to replace with AsyncImage when it is fixed with lazy views
|
||||
URLImage(video.thumbnailURL) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
Section {
|
||||
if let thumbnail = video.thumbnailURL {
|
||||
// to replace with AsyncImage when it is fixed with lazy views
|
||||
URLImage(thumbnail) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: 320, height: 180)
|
||||
}
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
.frame(width: 320, height: 180)
|
||||
} else {
|
||||
Image(systemName: "exclamationmark.square")
|
||||
}
|
||||
}
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
.frame(width: 320, height: 180)
|
||||
|
||||
HStack {
|
||||
@@ -68,7 +75,8 @@ struct VideoThumbnailView_Previews: PreviewProvider {
|
||||
thumbnailURL: URL(string: "https://invidious.home.arekf.net/vi/yXohcxCKqvo/maxres.jpg")!,
|
||||
author: "Bear",
|
||||
length: 240,
|
||||
published: "2 days ago"
|
||||
published: "2 days ago",
|
||||
channelID: ""
|
||||
)).frame(maxWidth: 350)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user