remove filters from filter view

This commit is contained in:
Trey t
2022-03-31 11:26:17 -05:00
parent 11df386cfc
commit 91fe4dcf79

View File

@@ -13,7 +13,6 @@ struct FilterView: View {
let months = [(0, "J"), (1, "F"), (2,"M"), (3,"A"), (4,"M"), (5, "J"), (6,"J"), (7,"A"), (8,"S"), (9,"O"), (10, "N"), (11,"D")]
@State private var toggle = true
@State private var showFilter = false
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \MoodEntry.forDate, ascending: false)],
@@ -45,27 +44,22 @@ struct FilterView: View {
]
var body: some View {
VStack {
filterButon
.padding([.leading, .trailing, .top])
statsView
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 90, maxHeight: 90)
.cornerRadius(10)
.padding()
Text(String(localized: "filter_view_total") + ": \(self.viewModel.numberOfRatings)")
.font(.title2)
.foregroundColor(textColor)
if showFilter {
filterView
ScrollView {
VStack {
statsView
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 90, maxHeight: 90)
.cornerRadius(10)
.padding()
Text(String(localized: "filter_view_total") + ": \(self.viewModel.numberOfRatings)")
.font(.title2)
.foregroundColor(textColor)
gridView
.onAppear(perform: {
self.viewModel.filterEntries(startDate: Date(timeIntervalSince1970: 0), endDate: Date())
})
}
gridView
.onAppear(perform: {
self.viewModel.filterEntries(startDate: Date(timeIntervalSince1970: 0), endDate: Date())
})
}
.padding(.bottom, 5)
.background(
@@ -74,21 +68,6 @@ struct FilterView: View {
)
}
private var filterButon: some View {
Button(action: {
withAnimation{
showFilter.toggle()
}
}, label: {
Text(showFilter ? String(localized: "filter_view_hide_filters") : String(localized: "filter_view_show_filters"))
.frame(maxWidth: .infinity)
.frame(height: 44)
.foregroundColor(textColor)
.background(theme.currentTheme.secondaryBGColor)
.cornerRadius(10)
}).frame(maxWidth: .infinity)
}
struct StatsSubView: View {
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@@ -127,75 +106,6 @@ struct FilterView: View {
.cornerRadius(10)
}
private var filterView: some View {
VStack {
VStack {
ZStack {
theme.currentTheme.secondaryBGColor
DatePicker(
String(localized: "filter_view_begin_date"),
selection: $viewModel.entryStartDate,
displayedComponents: [.date]
).onChange(of: viewModel.entryStartDate, perform: { value in
viewModel.filterEntries(startDate: viewModel.entryStartDate, endDate: viewModel.entryEndDate)
})
.padding()
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 44, maxHeight: 44)
.cornerRadius(10)
.padding([.leading, .trailing])
.foregroundColor(textColor)
.accentColor(textColor)
ZStack {
theme.currentTheme.secondaryBGColor
DatePicker(
String(localized: "filter_view_end_date"),
selection: $viewModel.entryEndDate,
displayedComponents: [.date]
).onChange(of: viewModel.entryStartDate, perform: { value in
viewModel.filterEntries(startDate: viewModel.entryStartDate, endDate: viewModel.entryEndDate)
})
.padding()
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 44, maxHeight: 44)
.cornerRadius(10)
.padding([.leading, .trailing])
.foregroundColor(textColor)
.accentColor(textColor)
ZStack {
theme.currentTheme.secondaryBGColor
HStack {
Spacer()
ForEach(weekdays.indices, id: \.self) { dayIdx in
let day = String(weekdays[dayIdx].0)
let value = weekdays[dayIdx].1
Button(day.capitalized, action: {
if let index = viewModel.selectedDays.firstIndex(of: value) {
viewModel.selectedDays.remove(at: index)
} else {
viewModel.selectedDays.append(value)
}
viewModel.filterEntries(startDate: viewModel.entryStartDate,
endDate: viewModel.entryEndDate)
})
.frame(maxWidth: .infinity)
.foregroundColor(viewModel.selectedDays.contains(value) || viewModel.selectedDays.isEmpty ? .green : .red)
}
Spacer()
}
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 44, maxHeight: 44)
.cornerRadius(10)
.padding([ .leading, .trailing])
}
filterButon
.padding([.leading, .trailing, .top])
}
}
private var monthsHeader: some View {
LazyVGrid(columns: columns, spacing: 0) {
ForEach(months, id: \.self.0) { item in
@@ -213,24 +123,17 @@ struct FilterView: View {
.padding([.leading, .trailing])
VStack {
ScrollView {
ForEach(Array(self.viewModel.data.keys.sorted(by: >)), id: \.self) { yearKey in
let yearData = self.viewModel.data[yearKey]!
Text(String(yearKey))
.font(.title)
.foregroundColor(textColor)
yearGridView(yearData: yearData, columns: columns)
.background(
theme.currentTheme.secondaryBGColor
)
.cornerRadius(10)
}
ForEach(Array(self.viewModel.data.keys.sorted(by: >)), id: \.self) { yearKey in
let yearData = self.viewModel.data[yearKey]!
Text(String(yearKey))
.font(.title)
.foregroundColor(textColor)
yearGridView(yearData: yearData, columns: columns)
.background(
theme.currentTheme.secondaryBGColor
)
.cornerRadius(10)
}
.simultaneousGesture(DragGesture().onChanged({ _ in
withAnimation{
showFilter = false
}
}))
.padding([.top, .leading, .trailing])
}
}