mirror of
https://github.com/yattee/yattee.git
synced 2026-11-01 01:17:20 +00:00
Move comments pill mode into the comments page settings
The pill mode now lives on CommentsPageSettings and is edited in the comments page editor instead of a standalone settings section. The legacy value on PlayerPillSettings is kept for decoding old presets and migrated by effectivePanelSettings. Comments are loaded when either the comments page is enabled or the pill is not disabled.
This commit is contained in:
@@ -147,11 +147,42 @@ struct InfoPageSettings: Codable, Hashable, Sendable {
|
||||
var effectiveShowDescription: Bool { showDescription ?? true }
|
||||
}
|
||||
|
||||
// MARK: - Comments Pill Mode
|
||||
|
||||
/// Controls how the comments pill is displayed in the player.
|
||||
/// Stored on the comments page settings (moved from the player pill settings;
|
||||
/// `PlayerControlsLayout.effectivePanelSettings` migrates the legacy value).
|
||||
enum CommentsPillMode: String, Codable, Hashable, Sendable, CaseIterable {
|
||||
case pill // Default - shows expanded pill, collapses on scroll
|
||||
case button // Always show collapsed (button-only)
|
||||
case disabled // No button/pill visible
|
||||
|
||||
/// Localized display name for settings UI.
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .pill:
|
||||
return String(localized: "commentsPill.mode.pill")
|
||||
case .button:
|
||||
return String(localized: "commentsPill.mode.button")
|
||||
case .disabled:
|
||||
return String(localized: "commentsPill.mode.disabled")
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the comments pill should always be collapsed (button mode).
|
||||
var alwaysCollapsed: Bool {
|
||||
self == .button
|
||||
}
|
||||
}
|
||||
|
||||
/// Element toggles for the comments page.
|
||||
struct CommentsPageSettings: Codable, Hashable, Sendable {
|
||||
var showAvatars: Bool?
|
||||
/// How the comments pill (portrait/floating panel) is displayed.
|
||||
var pillMode: CommentsPillMode?
|
||||
|
||||
var effectiveShowAvatars: Bool { showAvatars ?? true }
|
||||
var effectivePillMode: CommentsPillMode { pillMode ?? .pill }
|
||||
}
|
||||
|
||||
/// Element toggles for the related videos page.
|
||||
@@ -418,6 +449,17 @@ struct PanelSettings: Codable, Hashable, Sendable {
|
||||
enabledPages().contains { $0.pageType == pageType }
|
||||
}
|
||||
|
||||
/// The comments pill mode from the comments page settings.
|
||||
var commentsPillMode: CommentsPillMode {
|
||||
configuration(for: .comments)?.commentsSettings.effectivePillMode ?? .pill
|
||||
}
|
||||
|
||||
/// Whether comments should be loaded from the API: needed by the comments
|
||||
/// page (when enabled) and by the pill (unless disabled).
|
||||
var shouldLoadComments: Bool {
|
||||
isPageEnabled(.comments) || commentsPillMode != .disabled
|
||||
}
|
||||
|
||||
/// The stored configuration for a page type, if present.
|
||||
func configuration(for pageType: PanelPageType) -> PanelPageConfiguration? {
|
||||
normalizedPages.first { $0.pageType == pageType }
|
||||
|
||||
@@ -100,8 +100,18 @@ struct PlayerControlsLayout: Codable, Hashable, Sendable {
|
||||
// MARK: - Panel Settings
|
||||
|
||||
/// Returns the effective details panel settings, using defaults if not set.
|
||||
/// Migrates the legacy comments pill mode (once stored on the player pill
|
||||
/// settings) into the comments page settings; the migrated value persists
|
||||
/// the first time the panel settings are edited and saved.
|
||||
var effectivePanelSettings: PanelSettings {
|
||||
panelSettings ?? .default
|
||||
var settings = panelSettings ?? .default
|
||||
if let legacyMode = playerPillSettings?.commentsPillMode,
|
||||
settings.configuration(for: .comments)?.commentsSettings.pillMode == nil {
|
||||
var comments = settings.configuration(for: .comments)?.commentsSettings ?? CommentsPageSettings()
|
||||
comments.pillMode = legacyMode
|
||||
settings.updateSettings(.comments(comments), for: .comments)
|
||||
}
|
||||
return settings
|
||||
}
|
||||
|
||||
// MARK: - Defaults
|
||||
|
||||
@@ -8,37 +8,6 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - CommentsPillMode
|
||||
|
||||
/// Controls how the comments pill is displayed in the player.
|
||||
enum CommentsPillMode: String, Codable, Hashable, Sendable, CaseIterable {
|
||||
case pill // Default - shows expanded pill, collapses on scroll
|
||||
case button // Always show collapsed (button-only)
|
||||
case disabled // No button/pill visible, no API query
|
||||
|
||||
/// Localized display name for settings UI.
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .pill:
|
||||
return String(localized: "commentsPill.mode.pill")
|
||||
case .button:
|
||||
return String(localized: "commentsPill.mode.button")
|
||||
case .disabled:
|
||||
return String(localized: "commentsPill.mode.disabled")
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether comments should be loaded from the API.
|
||||
var shouldLoadComments: Bool {
|
||||
self != .disabled
|
||||
}
|
||||
|
||||
/// Whether the comments pill should always be collapsed (button mode).
|
||||
var alwaysCollapsed: Bool {
|
||||
self == .button
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - PillVisibility
|
||||
|
||||
/// Controls when the player pill is visible based on orientation.
|
||||
@@ -89,7 +58,9 @@ struct PlayerPillSettings: Codable, Hashable, Sendable {
|
||||
/// Ordered list of buttons to display in the pill.
|
||||
var buttons: [ControlButtonConfiguration]
|
||||
|
||||
/// How the comments pill should be displayed (optional for backward compatibility).
|
||||
/// Legacy: the comments pill mode now lives on the comments page settings
|
||||
/// (`CommentsPageSettings.pillMode`). Kept only so old presets decode;
|
||||
/// `PlayerControlsLayout.effectivePanelSettings` migrates it.
|
||||
var commentsPillMode: CommentsPillMode?
|
||||
|
||||
// MARK: - Initialization
|
||||
@@ -104,28 +75,6 @@ struct PlayerPillSettings: Codable, Hashable, Sendable {
|
||||
self.commentsPillMode = commentsPillMode
|
||||
}
|
||||
|
||||
// MARK: - Computed Properties
|
||||
|
||||
/// Returns the effective comments pill mode, defaulting to `.pill` when nil.
|
||||
var effectiveCommentsPillMode: CommentsPillMode {
|
||||
commentsPillMode ?? .pill
|
||||
}
|
||||
|
||||
/// Whether comments should be loaded from the API.
|
||||
var shouldLoadComments: Bool {
|
||||
effectiveCommentsPillMode.shouldLoadComments
|
||||
}
|
||||
|
||||
/// Whether the comments pill should always be shown collapsed.
|
||||
var isCommentsPillAlwaysCollapsed: Bool {
|
||||
effectiveCommentsPillMode.alwaysCollapsed
|
||||
}
|
||||
|
||||
/// Whether the comments pill should be visible at all.
|
||||
var shouldShowCommentsPill: Bool {
|
||||
effectiveCommentsPillMode != .disabled
|
||||
}
|
||||
|
||||
// MARK: - Mutation Helpers
|
||||
|
||||
/// Adds a button of the given type to the pill.
|
||||
|
||||
Reference in New Issue
Block a user