yattee/Apple TV/SearchedVideosView.swift
Arkadiusz Fal 4bc70f351d Add search
2021-06-11 14:36:26 +02:00

48 lines
1.2 KiB
Swift

import SwiftUI
struct SearchedVideosView: View {
@ObservedObject var provider: SearchedVideosProvider
@Binding var query: String
@Environment(\.isSearching) var isSearching
var body: some View {
Group {
List {
ForEach(videos) { video in
VideoThumbnailView(video: video)
.listRowInsets(listRowInsets)
}
}
.listStyle(GroupedListStyle())
}
}
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 {
newQuery = id
}
if (newQuery != provider.query) {
provider.query = newQuery
provider.load()
}
return provider.videos
}
}
//struct SearchedVideosView_Previews: PreviewProvider {
// static var previews: some View {
// SearchedVideosView()
// }
//}