yattee/Apple TV/SearchOptionsView.swift

65 lines
2.0 KiB
Swift
Raw Normal View History

2021-07-07 22:39:18 +00:00
import Defaults
import SwiftUI
struct SearchOptionsView: View {
@Default(.searchSortOrder) private var searchSortOrder
@Default(.searchDate) private var searchDate
@Default(.searchDuration) private var searchDuration
var body: some View {
2021-07-08 15:14:54 +00:00
CoverSectionView("Search Options") {
CoverSectionRowView("Sort By") { searchSortOrderButton }
CoverSectionRowView("Upload date") { searchDateButton }
CoverSectionRowView("Duration") { searchDurationButton }
2021-07-07 22:39:18 +00:00
}
}
var searchSortOrderButton: some View {
Button(self.searchSortOrder.name) {
self.searchSortOrder = self.searchSortOrder.next()
}
.contextMenu {
2021-07-22 12:43:13 +00:00
ForEach(SearchQuery.SortOrder.allCases) { sortOrder in
2021-07-07 22:39:18 +00:00
Button(sortOrder.name) {
self.searchSortOrder = sortOrder
}
}
}
}
var searchDateButton: some View {
Button(self.searchDate?.name ?? "All") {
2021-07-22 12:43:13 +00:00
self.searchDate = self.searchDate == nil ? SearchQuery.Date.allCases.first : self.searchDate!.next(nilAtEnd: true)
2021-07-07 22:39:18 +00:00
}
.contextMenu {
2021-07-22 12:43:13 +00:00
ForEach(SearchQuery.Date.allCases) { searchDate in
2021-07-07 22:39:18 +00:00
Button(searchDate.name) {
self.searchDate = searchDate
}
}
Button("Reset") {
self.searchDate = nil
}
}
}
var searchDurationButton: some View {
Button(self.searchDuration?.name ?? "All") {
2021-07-22 12:43:13 +00:00
self.searchDuration = self.searchDuration == nil ? SearchQuery.Duration.allCases.first : self.searchDuration!.next(nilAtEnd: true)
2021-07-07 22:39:18 +00:00
}
.contextMenu {
2021-07-22 12:43:13 +00:00
ForEach(SearchQuery.Duration.allCases) { searchDuration in
2021-07-07 22:39:18 +00:00
Button(searchDuration.name) {
2021-07-08 15:14:54 +00:00
self.searchDuration = searchDuration
2021-07-07 22:39:18 +00:00
}
}
Button("Reset") {
2021-07-08 15:14:54 +00:00
self.searchDuration = nil
2021-07-07 22:39:18 +00:00
}
}
}
}