Files
Reflect/FeelsWidget2/WidgetModels.swift
Trey t 2de96495e0 Fix vote widget to show actual voting date instead of hardcoded Today
When rating for a previous day (e.g., rating last night for yesterday),
the medium vote widget now correctly shows the date like "Sun, Dec 28"
instead of always displaying "Today".

- Add votingDate property to VoteWidgetEntry
- Add dynamic date formatting in VotedStatsView
- Update all preview entries with votingDate parameter

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 10:06:15 -06:00

78 lines
1.9 KiB
Swift

//
// WidgetModels.swift
// FeelsWidget
//
// Data models for widget timeline entries
//
import WidgetKit
import SwiftUI
import Intents
// MARK: - Timeline View Model
class WatchTimelineView: Identifiable {
let id = UUID()
let image: Image
let graphic: Image
let date: Date
let color: Color
let secondaryColor: Color
let mood: Mood
init(image: Image, graphic: Image, date: Date, color: Color, secondaryColor: Color, mood: Mood) {
self.image = image
self.date = date
self.color = color
self.graphic = graphic
self.secondaryColor = secondaryColor
self.mood = mood
}
}
// MARK: - Timeline Widget Entry
struct SimpleEntry: TimelineEntry {
let date: Date
let configuration: ConfigurationIntent
let timeLineViews: [WatchTimelineView]?
let showStats: Bool
let hasSubscription: Bool
let hasVotedToday: Bool
let promptText: String
init(date: Date, configuration: ConfigurationIntent, timeLineViews: [WatchTimelineView]?, showStats: Bool = false, hasSubscription: Bool = false, hasVotedToday: Bool = true, promptText: String = "") {
self.date = date
self.configuration = configuration
self.timeLineViews = timeLineViews
self.showStats = showStats
self.hasSubscription = hasSubscription
self.hasVotedToday = hasVotedToday
self.promptText = promptText
}
}
// MARK: - Vote Widget Entry
struct VoteWidgetEntry: TimelineEntry {
let date: Date
let votingDate: Date
let hasSubscription: Bool
let hasVotedToday: Bool
let todaysMood: Mood?
let stats: MoodStats?
let promptText: String
}
// MARK: - Mood Stats
struct MoodStats {
let totalEntries: Int
let moodCounts: [Mood: Int]
func percentage(for mood: Mood) -> Double {
guard totalEntries > 0 else { return 0 }
return Double(moodCounts[mood, default: 0]) / Double(totalEntries) * 100
}
}