1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Model/Search/SearchQuery.swift

75 lines
1.8 KiB
Swift
Raw Normal View History

2021-07-22 18:13:13 +05:30
import Defaults
2021-07-08 04:09:18 +05:30
import Foundation
final class SearchQuery: ObservableObject {
2021-11-02 03:26:18 +05:30
enum Date: String, CaseIterable, Identifiable {
case any, hour, today, week, month, year
2021-07-22 18:13:13 +05:30
var id: SearchQuery.Date.RawValue {
rawValue
}
var name: String {
2022-09-04 20:58:30 +05:30
rawValue.capitalized.localized()
2021-07-22 18:13:13 +05:30
}
}
2021-11-02 03:26:18 +05:30
enum Duration: String, CaseIterable, Identifiable {
case any, short, long
2021-07-22 18:13:13 +05:30
var id: SearchQuery.Duration.RawValue {
rawValue
}
var name: String {
2022-09-04 20:58:30 +05:30
rawValue.capitalized.localized()
2021-07-22 18:13:13 +05:30
}
}
2021-11-02 03:26:18 +05:30
enum SortOrder: String, CaseIterable, Identifiable {
2021-07-22 18:13:13 +05:30
case relevance, rating, uploadDate, viewCount
var id: SearchQuery.SortOrder.RawValue {
rawValue
}
var name: String {
switch self {
case .uploadDate:
2022-09-04 20:58:30 +05:30
return "Date".localized()
2021-07-22 18:13:13 +05:30
case .viewCount:
2022-09-04 20:58:30 +05:30
return "Views".localized()
2021-07-22 18:13:13 +05:30
default:
2022-09-04 20:58:30 +05:30
return rawValue.capitalized.localized()
2021-07-22 18:13:13 +05:30
}
}
var parameter: String {
switch self {
case .uploadDate:
return "upload_date"
case .viewCount:
return "view_count"
default:
return rawValue
}
}
}
2021-07-08 04:09:18 +05:30
@Published var query: String
2021-07-22 18:13:13 +05:30
@Published var sortBy: SearchQuery.SortOrder = .relevance
@Published var date: SearchQuery.Date? = .month
@Published var duration: SearchQuery.Duration?
2021-07-08 04:09:18 +05:30
init(query: String = "", sortBy: SearchQuery.SortOrder = .relevance, date: SearchQuery.Date? = nil, duration: SearchQuery.Duration? = nil) {
2021-07-08 04:09:18 +05:30
self.query = query
self.sortBy = sortBy
self.date = date
self.duration = duration
}
2021-07-12 02:22:49 +05:30
var isEmpty: Bool {
query.isEmpty
}
2021-07-08 04:09:18 +05:30
}