each year view has a stats header
This commit is contained in:
@@ -46,22 +46,11 @@ struct YearView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
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
|
gridView
|
||||||
.onAppear(perform: {
|
.onAppear(perform: {
|
||||||
self.viewModel.filterEntries(startDate: Date(timeIntervalSince1970: 0), endDate: Date())
|
self.viewModel.filterEntries(startDate: Date(timeIntervalSince1970: 0), endDate: Date())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.padding(.bottom, 5)
|
.padding(.bottom, 5)
|
||||||
.background(
|
.background(
|
||||||
theme.currentTheme.bg
|
theme.currentTheme.bg
|
||||||
@@ -69,44 +58,6 @@ struct YearView: View {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
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
|
||||||
@@ -119,16 +70,48 @@ struct YearView: View {
|
|||||||
|
|
||||||
private var gridView: some View {
|
private var gridView: some View {
|
||||||
VStack {
|
VStack {
|
||||||
monthsHeader
|
|
||||||
.cornerRadius(10)
|
|
||||||
.padding([.leading, .trailing])
|
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
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]!
|
||||||
|
|
||||||
|
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))
|
Text(String(yearKey))
|
||||||
.font(.title)
|
.font(.title)
|
||||||
.foregroundColor(textColor)
|
.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)
|
yearGridView(yearData: yearData, columns: columns)
|
||||||
.background(
|
.background(
|
||||||
theme.currentTheme.secondaryBGColor
|
theme.currentTheme.secondaryBGColor
|
||||||
|
|||||||
Reference in New Issue
Block a user