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")] 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 toggle = true
@State private var showFilter = false
@FetchRequest( @FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \MoodEntry.forDate, ascending: false)], sortDescriptors: [NSSortDescriptor(keyPath: \MoodEntry.forDate, ascending: false)],
@@ -45,27 +44,22 @@ struct FilterView: View {
] ]
var body: some View { var body: some View {
VStack { ScrollView {
filterButon VStack {
.padding([.leading, .trailing, .top]) statsView
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 90, maxHeight: 90)
.cornerRadius(10)
.padding()
statsView Text(String(localized: "filter_view_total") + ": \(self.viewModel.numberOfRatings)")
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 90, maxHeight: 90) .font(.title2)
.cornerRadius(10) .foregroundColor(textColor)
.padding()
Text(String(localized: "filter_view_total") + ": \(self.viewModel.numberOfRatings)") gridView
.font(.title2) .onAppear(perform: {
.foregroundColor(textColor) self.viewModel.filterEntries(startDate: Date(timeIntervalSince1970: 0), endDate: Date())
})
if showFilter {
filterView
} }
gridView
.onAppear(perform: {
self.viewModel.filterEntries(startDate: Date(timeIntervalSince1970: 0), endDate: Date())
})
} }
.padding(.bottom, 5) .padding(.bottom, 5)
.background( .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 { struct StatsSubView: View {
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default @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 @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@@ -127,75 +106,6 @@ struct FilterView: View {
.cornerRadius(10) .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 { private var monthsHeader: some View {
LazyVGrid(columns: columns, spacing: 0) { LazyVGrid(columns: columns, spacing: 0) {
ForEach(months, id: \.self.0) { item in ForEach(months, id: \.self.0) { item in
@@ -213,24 +123,17 @@ struct FilterView: View {
.padding([.leading, .trailing]) .padding([.leading, .trailing])
VStack { VStack {
ScrollView { ForEach(Array(self.viewModel.data.keys.sorted(by: >)), id: \.self) { yearKey in
ForEach(Array(self.viewModel.data.keys.sorted(by: >)), id: \.self) { yearKey in let yearData = self.viewModel.data[yearKey]!
let yearData = self.viewModel.data[yearKey]! Text(String(yearKey))
Text(String(yearKey)) .font(.title)
.font(.title) .foregroundColor(textColor)
.foregroundColor(textColor) yearGridView(yearData: yearData, columns: columns)
yearGridView(yearData: yearData, columns: columns) .background(
.background( theme.currentTheme.secondaryBGColor
theme.currentTheme.secondaryBGColor )
) .cornerRadius(10)
.cornerRadius(10)
}
} }
.simultaneousGesture(DragGesture().onChanged({ _ in
withAnimation{
showFilter = false
}
}))
.padding([.top, .leading, .trailing]) .padding([.top, .leading, .trailing])
} }
} }