1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 22:30:32 +05:30
yattee/tvOS/Options/SearchOptionsView.swift

65 lines
2.0 KiB
Swift
Raw Normal View History

2021-07-08 04:09:18 +05:30
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 20:44:54 +05:30
CoverSectionView("Search Options") {
CoverSectionRowView("Sort By") { searchSortOrderButton }
CoverSectionRowView("Upload date") { searchDateButton }
CoverSectionRowView("Duration") { searchDurationButton }
2021-07-08 04:09:18 +05:30
}
}
var searchSortOrderButton: some View {
Button(self.searchSortOrder.name) {
self.searchSortOrder = self.searchSortOrder.next()
}
.contextMenu {
2021-07-22 18:13:13 +05:30
ForEach(SearchQuery.SortOrder.allCases) { sortOrder in
2021-07-08 04:09:18 +05:30
Button(sortOrder.name) {
self.searchSortOrder = sortOrder
}
}
}
}
var searchDateButton: some View {
Button(self.searchDate?.name ?? "All") {
2021-07-22 18:13:13 +05:30
self.searchDate = self.searchDate == nil ? SearchQuery.Date.allCases.first : self.searchDate!.next(nilAtEnd: true)
2021-07-08 04:09:18 +05:30
}
.contextMenu {
2021-07-22 18:13:13 +05:30
ForEach(SearchQuery.Date.allCases) { searchDate in
2021-07-08 04:09:18 +05:30
Button(searchDate.name) {
self.searchDate = searchDate
}
}
Button("Reset") {
self.searchDate = nil
}
}
}
var searchDurationButton: some View {
Button(self.searchDuration?.name ?? "All") {
2021-07-22 18:13:13 +05:30
self.searchDuration = self.searchDuration == nil ? SearchQuery.Duration.allCases.first : self.searchDuration!.next(nilAtEnd: true)
2021-07-08 04:09:18 +05:30
}
.contextMenu {
2021-07-22 18:13:13 +05:30
ForEach(SearchQuery.Duration.allCases) { searchDuration in
2021-07-08 04:09:18 +05:30
Button(searchDuration.name) {
2021-07-08 20:44:54 +05:30
self.searchDuration = searchDuration
2021-07-08 04:09:18 +05:30
}
}
Button("Reset") {
2021-07-08 20:44:54 +05:30
self.searchDuration = nil
2021-07-08 04:09:18 +05:30
}
}
}
}