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 {
ForEach(SearchSortOrder.allCases) { sortOrder in
Button(sortOrder.name) {
self.searchSortOrder = sortOrder
}
}
}
}
var searchDateButton: some View {
Button(self.searchDate?.name ?? "All") {
self.searchDate = self.searchDate == nil ? SearchDate.allCases.first : self.searchDate!.next(nilAtEnd: true)
}
.contextMenu {
ForEach(SearchDate.allCases) { searchDate in
Button(searchDate.name) {
self.searchDate = searchDate
}
}
Button("Reset") {
self.searchDate = nil
}
}
}
var searchDurationButton: some View {
Button(self.searchDuration?.name ?? "All") {
2021-07-08 15:14:54 +00:00
self.searchDuration = self.searchDuration == nil ? SearchDuration.allCases.first : self.searchDuration!.next(nilAtEnd: true)
2021-07-07 22:39:18 +00:00
}
.contextMenu {
ForEach(SearchDuration.allCases) { searchDuration in
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
}
}
}
}