mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Add hiding short videos
This commit is contained in:
@@ -5,21 +5,32 @@ struct ContentItemView: View {
|
||||
let item: ContentItem
|
||||
@Environment(\.listingStyle) private var listingStyle
|
||||
@Environment(\.noListingDividers) private var noListingDividers
|
||||
@Environment(\.hideShorts) private var hideShorts
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
switch item.contentType {
|
||||
case .video:
|
||||
videoItem(item.video)
|
||||
case .channel:
|
||||
channelItem(item.channel)
|
||||
case .playlist:
|
||||
playlistItem(item.playlist)
|
||||
default:
|
||||
placeholderItem()
|
||||
@ViewBuilder var body: some View {
|
||||
if itemVisible {
|
||||
Group {
|
||||
switch item.contentType {
|
||||
case .video:
|
||||
videoItem(item.video)
|
||||
case .channel:
|
||||
channelItem(item.channel)
|
||||
case .playlist:
|
||||
playlistItem(item.playlist)
|
||||
default:
|
||||
placeholderItem()
|
||||
}
|
||||
}
|
||||
.id(item.cacheKey)
|
||||
}
|
||||
.id(item.cacheKey)
|
||||
}
|
||||
|
||||
var itemVisible: Bool {
|
||||
guard hideShorts, item.contentType == .video, let video = item.video else {
|
||||
return true
|
||||
}
|
||||
|
||||
return !video.short
|
||||
}
|
||||
|
||||
@ViewBuilder func videoItem(_ video: Video) -> some View {
|
||||
|
33
Shared/Views/HideShortsButtons.swift
Normal file
33
Shared/Views/HideShortsButtons.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
import SwiftUI
|
||||
|
||||
struct HideShortsButtons: View {
|
||||
@Binding var hide: Bool
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
hide.toggle()
|
||||
} label: {
|
||||
Group {
|
||||
if hide {
|
||||
Label("Short videos: hidden", systemImage: "bolt.slash.fill")
|
||||
.help("Short videos: hidden")
|
||||
} else {
|
||||
Label("Short videos: visible", systemImage: "bolt.fill")
|
||||
.help("Short videos: visible")
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
.font(.caption2)
|
||||
.imageScale(.small)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct HideShortsButtons_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
HideShortsButtons(hide: .constant(true))
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,6 +10,7 @@ struct PopularView: View {
|
||||
@State private var error: RequestError?
|
||||
|
||||
@Default(.popularListingStyle) private var popularListingStyle
|
||||
@Default(.hideShorts) private var hideShorts
|
||||
|
||||
var resource: Resource? {
|
||||
accounts.api.popular
|
||||
@@ -69,6 +70,10 @@ struct PopularView: View {
|
||||
ToolbarItem {
|
||||
ListingStyleButtons(listingStyle: $popularListingStyle)
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
}
|
||||
#else
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
@@ -84,6 +89,10 @@ struct PopularView: View {
|
||||
Menu {
|
||||
ListingStyleButtons(listingStyle: $popularListingStyle)
|
||||
|
||||
Section {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
Section {
|
||||
SettingsButtons()
|
||||
}
|
||||
|
Reference in New Issue
Block a user