Fix Month view showing fake data and show all 5 moods in exports
- Fix critical bug in generateObjectNotInArray() that ignored the mood parameter and generated random moods instead of placeholders, causing Month view to display fake colored entries for days without real data - Update Month and Year shareableView exports to show all 5 mood types even when some have 0 entries (previously filtered out empty moods) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -48,14 +48,9 @@ extension DataController {
|
|||||||
|
|
||||||
/// Creates an entry that is NOT inserted into the context - used for UI placeholders
|
/// Creates an entry that is NOT inserted into the context - used for UI placeholders
|
||||||
func generateObjectNotInArray(forDate date: Date = Date(), withMood mood: Mood = .placeholder) -> MoodEntryModel {
|
func generateObjectNotInArray(forDate date: Date = Date(), withMood mood: Mood = .placeholder) -> MoodEntryModel {
|
||||||
var moodValue = Int.random(in: 2...4)
|
|
||||||
if Int.random(in: 0...400) % 5 == 0 {
|
|
||||||
moodValue = Int.random(in: 0...4)
|
|
||||||
}
|
|
||||||
|
|
||||||
let entry = MoodEntryModel(
|
let entry = MoodEntryModel(
|
||||||
forDate: date,
|
forDate: date,
|
||||||
moodValue: moodValue,
|
moodValue: mood.rawValue,
|
||||||
entryType: EntryType.listView.rawValue,
|
entryType: EntryType.listView.rawValue,
|
||||||
canEdit: false,
|
canEdit: false,
|
||||||
canDelete: false
|
canDelete: false
|
||||||
|
|||||||
@@ -292,6 +292,11 @@ struct MonthCard: View, Equatable {
|
|||||||
cachedMetrics.filter { $0.total > 0 }.sorted { $0.mood.rawValue > $1.mood.rawValue }
|
cachedMetrics.filter { $0.total > 0 }.sorted { $0.mood.rawValue > $1.mood.rawValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All 5 moods for share view (shows 0% for moods with no entries)
|
||||||
|
private var allMoodMetrics: [MoodMetrics] {
|
||||||
|
cachedMetrics.sorted { $0.mood.rawValue > $1.mood.rawValue }
|
||||||
|
}
|
||||||
|
|
||||||
private var topMood: Mood? {
|
private var topMood: Mood? {
|
||||||
displayMetrics.max(by: { $0.total < $1.total })?.mood
|
displayMetrics.max(by: { $0.total < $1.total })?.mood
|
||||||
}
|
}
|
||||||
@@ -355,9 +360,9 @@ struct MonthCard: View, Equatable {
|
|||||||
}
|
}
|
||||||
.padding(.bottom, 30)
|
.padding(.bottom, 30)
|
||||||
|
|
||||||
// Mood breakdown with bars
|
// Mood breakdown with bars (all 5 moods)
|
||||||
VStack(spacing: 12) {
|
VStack(spacing: 12) {
|
||||||
ForEach(displayMetrics) { metric in
|
ForEach(allMoodMetrics) { metric in
|
||||||
HStack(spacing: 12) {
|
HStack(spacing: 12) {
|
||||||
Circle()
|
Circle()
|
||||||
.fill(moodTint.color(forMood: metric.mood))
|
.fill(moodTint.color(forMood: metric.mood))
|
||||||
@@ -376,9 +381,11 @@ struct MonthCard: View, Equatable {
|
|||||||
RoundedRectangle(cornerRadius: 6)
|
RoundedRectangle(cornerRadius: 6)
|
||||||
.fill(Color.gray.opacity(0.2))
|
.fill(Color.gray.opacity(0.2))
|
||||||
|
|
||||||
RoundedRectangle(cornerRadius: 6)
|
if metric.percent > 0 {
|
||||||
.fill(moodTint.color(forMood: metric.mood))
|
RoundedRectangle(cornerRadius: 6)
|
||||||
.frame(width: max(8, geo.size.width * CGFloat(metric.percent / 100)))
|
.fill(moodTint.color(forMood: metric.mood))
|
||||||
|
.frame(width: max(8, geo.size.width * CGFloat(metric.percent / 100)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(height: 12)
|
.frame(height: 12)
|
||||||
|
|||||||
@@ -225,6 +225,11 @@ struct YearCard: View, Equatable {
|
|||||||
cachedMetrics.filter { $0.total > 0 }.sorted { $0.mood.rawValue > $1.mood.rawValue }
|
cachedMetrics.filter { $0.total > 0 }.sorted { $0.mood.rawValue > $1.mood.rawValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All 5 moods for share view (shows 0% for moods with no entries)
|
||||||
|
private var allMoodMetrics: [MoodMetrics] {
|
||||||
|
cachedMetrics.sorted { $0.mood.rawValue > $1.mood.rawValue }
|
||||||
|
}
|
||||||
|
|
||||||
private var totalEntries: Int {
|
private var totalEntries: Int {
|
||||||
yearEntries.filter { ![Mood.missing, Mood.placeholder].contains($0.mood) }.count
|
yearEntries.filter { ![Mood.missing, Mood.placeholder].contains($0.mood) }.count
|
||||||
}
|
}
|
||||||
@@ -290,7 +295,7 @@ struct YearCard: View, Equatable {
|
|||||||
|
|
||||||
// Mood breakdown with bars
|
// Mood breakdown with bars
|
||||||
VStack(spacing: 14) {
|
VStack(spacing: 14) {
|
||||||
ForEach(displayMetrics) { metric in
|
ForEach(allMoodMetrics) { metric in
|
||||||
HStack(spacing: 14) {
|
HStack(spacing: 14) {
|
||||||
Circle()
|
Circle()
|
||||||
.fill(moodTint.color(forMood: metric.mood))
|
.fill(moodTint.color(forMood: metric.mood))
|
||||||
@@ -309,9 +314,11 @@ struct YearCard: View, Equatable {
|
|||||||
RoundedRectangle(cornerRadius: 8)
|
RoundedRectangle(cornerRadius: 8)
|
||||||
.fill(Color.gray.opacity(0.2))
|
.fill(Color.gray.opacity(0.2))
|
||||||
|
|
||||||
RoundedRectangle(cornerRadius: 8)
|
if metric.percent > 0 {
|
||||||
.fill(moodTint.color(forMood: metric.mood))
|
RoundedRectangle(cornerRadius: 8)
|
||||||
.frame(width: max(8, geo.size.width * CGFloat(metric.percent / 100)))
|
.fill(moodTint.color(forMood: metric.mood))
|
||||||
|
.frame(width: max(8, geo.size.width * CGFloat(metric.percent / 100)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(height: 16)
|
.frame(height: 16)
|
||||||
|
|||||||
Reference in New Issue
Block a user