mirror of
https://github.com/yattee/yattee.git
synced 2024-12-26 23:43:41 +00:00
54 lines
1.9 KiB
Swift
54 lines
1.9 KiB
Swift
import Defaults
|
|
import Foundation
|
|
|
|
struct FavoriteItem: Codable, Equatable, Identifiable, Defaults.Serializable {
|
|
enum Section: Codable, Equatable, Defaults.Serializable {
|
|
case subscriptions
|
|
case popular
|
|
case trending(String, String?)
|
|
case channel(String, String)
|
|
case playlist(String)
|
|
case channelPlaylist(String, String)
|
|
case searchQuery(String, String, String, String)
|
|
|
|
var label: String {
|
|
switch self {
|
|
case .subscriptions:
|
|
return "Subscriptions"
|
|
case .popular:
|
|
return "Popular"
|
|
case let .trending(country, category):
|
|
let trendingCountry = Country(rawValue: country)!
|
|
let trendingCategory = category.isNil ? nil : TrendingCategory(rawValue: category!)
|
|
return "\(trendingCountry.flag) \(trendingCountry.id) \(trendingCategory?.name ?? "Trending")"
|
|
case let .channel(_, name):
|
|
return name
|
|
case let .channelPlaylist(_, name):
|
|
return name
|
|
case let .searchQuery(text, date, duration, order):
|
|
var label = "Search: \"\(text)\""
|
|
if !date.isEmpty, let date = SearchQuery.Date(rawValue: date), date != .any {
|
|
label += " from \(date == .today ? date.name : " this \(date.name)")"
|
|
}
|
|
if !order.isEmpty, let order = SearchQuery.SortOrder(rawValue: order), order != .relevance {
|
|
label += " by \(order.name)"
|
|
}
|
|
if !duration.isEmpty {
|
|
label += " (\(duration))"
|
|
}
|
|
|
|
return label
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
}
|
|
|
|
static func == (lhs: FavoriteItem, rhs: FavoriteItem) -> Bool {
|
|
lhs.section == rhs.section
|
|
}
|
|
|
|
var id = UUID().uuidString
|
|
var section: Section
|
|
}
|