each year view has a stats header

This commit is contained in:
Trey t
2022-03-31 15:39:08 -05:00
parent 627495336f
commit 3d1b7abc64

View File

@@ -46,21 +46,10 @@ struct YearView: View {
var body: some View {
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(
@@ -68,45 +57,7 @@ struct YearView: View {
.edgesIgnoringSafeArea(.all)
)
}
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
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
let data: [MoodEntry]
let mood: Mood
var body: some View {
VStack {
Text(String(Stats.getCountFor(moodType: mood,
inData: data)))
.font(.title)
.foregroundColor(textColor)
Text(mood.strValue)
.foregroundColor(moodTint.color(forMood: mood))
}
.onAppear(perform: {
EventLogger.log(event: "show_filter_view")
})
}
}
private var statsView: some View {
ZStack {
theme.currentTheme.secondaryBGColor
HStack {
Spacer()
ForEach(Mood.allValues, id: \.self) { mood in
StatsSubView(data: self.viewModel.uncategorizedData, mood: mood)
Spacer()
}
}
}
.cornerRadius(10)
}
private var monthsHeader: some View {
LazyVGrid(columns: columns, spacing: 0) {
ForEach(months, id: \.self.0) { item in
@@ -119,16 +70,48 @@ struct YearView: View {
private var gridView: some View {
VStack {
monthsHeader
.cornerRadius(10)
.padding([.leading, .trailing])
VStack {
VStack {
ForEach(Array(self.viewModel.data.keys.sorted(by: >)), id: \.self) { yearKey in
let yearData = self.viewModel.data[yearKey]!
let firstOfYear = Calendar.current.date(from: DateComponents(year: Int(yearKey), month: 1, day: 1))!
let lastOfYear = Calendar.current.date(from: DateComponents(year: Int(yearKey)+1, month: 1, day: 1))!
let yearEntries = PersistenceController.shared.getData(startDate: firstOfYear,
endDate: lastOfYear,
includedDays: daysFilter.currentFilters)
Text(String(yearKey))
.font(.title)
.foregroundColor(textColor)
ZStack {
theme.currentTheme.secondaryBGColor
HStack {
Spacer()
ForEach(Mood.allValues, id: \.self) { mood in
VStack {
Text(String(Stats.getCountFor(moodType: mood,
inData: yearEntries)))
.font(.title)
.foregroundColor(textColor)
Text(mood.strValue)
.foregroundColor(moodTint.color(forMood: mood))
}
Spacer()
}
}
}
.cornerRadius(10)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 90, maxHeight: 90)
.cornerRadius(10)
.padding()
Text(String(localized: "filter_view_total") + ": \(yearEntries.count)")
.font(.title2)
.foregroundColor(textColor)
monthsHeader
.cornerRadius(10)
yearGridView(yearData: yearData, columns: columns)
.background(
theme.currentTheme.secondaryBGColor