Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Sources/Kaset/Models/PlaylistSortOrder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Foundation

// MARK: - PlaylistSortKey

/// A sort key for the playlist detail track list.
enum PlaylistSortKey: String, CaseIterable, Identifiable {
case original
case title
case artist
case duration
case album

var id: String {
self.rawValue
}

var displayName: String {
switch self {
case .original: String(localized: "Original Order")
case .title: String(localized: "Title")
case .artist: String(localized: "Artist")
case .duration: String(localized: "Duration")
case .album: String(localized: "Album")
}
}
}

// MARK: - PlaylistSortOrder

/// A sort key plus direction. `.original` preserves the server-provided order.
struct PlaylistSortOrder: Equatable {
var key: PlaylistSortKey
var ascending: Bool

static let `default` = PlaylistSortOrder(key: .original, ascending: true)
}
10 changes: 10 additions & 0 deletions Sources/Kaset/Models/Song.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ struct Song: Identifiable, Codable, Hashable {
self.artists.map(\.name).joined(separator: ", ")
}

/// Stable per-occurrence identity, also safe as a SwiftUI `ForEach` id — position isn't
/// identity in a sortable list. The blank guard and namespacing prevent collisions: a
/// blank set id would collapse every such row onto one identity.
var rowIdentity: String {
if let setVideoId = self.playlistSetVideoId, !setVideoId.isEmpty {
return "set:\(setVideoId)"
}
return "video:\(self.videoId)"
}

/// Formatted duration string (e.g., "3:45").
var durationDisplay: String {
guard let duration else { return "--:--" }
Expand Down
Loading
Loading