Merge pull request #744 from stonerl/hide-comments

Allow hiding comments
This commit is contained in:
Arkadiusz Fal 2024-08-24 12:13:44 +02:00 committed by GitHub
commit ab493614ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 5 deletions

View File

@ -36,6 +36,8 @@ final class PlayerSettingsGroupExporter: SettingsGroupExporter {
export["pauseOnEnteringBackground"].bool = Defaults[.pauseOnEnteringBackground]
#endif
export["showComments"].bool = Defaults[.showComments]
#if !os(tvOS)
export["showScrollToTopInComments"].bool = Defaults[.showScrollToTopInComments]
#endif

View File

@ -83,6 +83,9 @@ struct PlayerSettingsGroupImporter {
}
#endif
if let showComments = json["showComments"].bool {
Defaults[.showComments] = showComments
}
#if !os(tvOS)
if let showScrollToTopInComments = json["showScrollToTopInComments"].bool {
Defaults[.showScrollToTopInComments] = showScrollToTopInComments

View File

@ -85,6 +85,7 @@ extension Defaults.Keys {
static let playerSidebar = Key<PlayerSidebarSetting>("playerSidebar", default: .defaultValue)
static let showKeywords = Key<Bool>("showKeywords", default: false)
static let showComments = Key<Bool>("showComments", default: true)
#if !os(tvOS)
static let showScrollToTopInComments = Key<Bool>("showScrollToTopInComments", default: true)
#endif

View File

@ -203,6 +203,7 @@ struct VideoDetails: View {
@Default(.showChapterThumbnails) private var showChapterThumbnails
@Default(.showChapterThumbnailsOnlyWhenDifferent) private var showChapterThumbnailsOnlyWhenDifferent
@Default(.showRelated) private var showRelated
@Default(.showComments) private var showComments
#if !os(tvOS)
@Default(.showScrollToTopInComments) private var showScrollToTopInComments
#endif
@ -300,6 +301,8 @@ struct VideoDetails: View {
switch page {
case .queue:
return !sidebarQueue && player.isAdvanceToNextItemAvailable
case .comments:
return showComments
default:
return !video.isLocal
}
@ -378,10 +381,12 @@ struct VideoDetails: View {
PlayerQueueView(sidebarQueue: false)
.padding(.horizontal)
case .comments:
CommentsView()
.onAppear {
comments.loadIfNeeded()
}
if showComments {
CommentsView()
.onAppear {
comments.loadIfNeeded()
}
}
}
}
.padding(.bottom, 60)

View File

@ -8,6 +8,7 @@ struct PlayerSettings: View {
@Default(.playerSidebar) private var playerSidebar
@Default(.showKeywords) private var showKeywords
@Default(.showComments) private var showComments
#if !os(tvOS)
@Default(.showScrollToTopInComments) private var showScrollToTopInComments
@Default(.collapsedLinesDescription) private var collapsedLinesDescription
@ -175,6 +176,7 @@ struct PlayerSettings: View {
if !accounts.isEmpty {
keywordsToggle
commentsToggle
#if !os(tvOS)
showScrollToTopInCommentsToggle
#endif
@ -250,9 +252,13 @@ struct PlayerSettings: View {
.modifier(SettingsPickerModifier())
}
private var commentsToggle: some View {
Toggle("Show comments", isOn: $showComments)
}
#if !os(tvOS)
private var showScrollToTopInCommentsToggle: some View {
Toggle("Show scroll to top button in comments", isOn: $showScrollToTopInComments)
Toggle("Show scroll to top button in comments", isOn: $showScrollToTopInComments).disabled(!showComments)
}
#endif