109 lines
4.1 KiB
Swift
109 lines
4.1 KiB
Swift
import WidgetKit
|
||
import Foundation
|
||
|
||
struct WidgetEntry: TimelineEntry {
|
||
let date: Date
|
||
let configuration: ConfigurationAppIntent
|
||
let completionRate: Double
|
||
let currentStreak: Int
|
||
let nextHabits: [HabitEntry]
|
||
let weeklyTrend: [Double]
|
||
let currentTimeOfDay: String
|
||
let currentTimeOfDaySymbol: String
|
||
let currentTimeOfDayRange: String
|
||
let nextRitualInfo: String?
|
||
}
|
||
|
||
// MARK: - Preview Helpers
|
||
|
||
extension WidgetEntry {
|
||
/// Creates a preview entry for a specific time of day
|
||
static func preview(
|
||
timeOfDay: String,
|
||
symbol: String,
|
||
range: String,
|
||
habits: [HabitEntry] = [],
|
||
completionRate: Double = 0.65,
|
||
streak: Int = 7,
|
||
nextRitual: String? = nil
|
||
) -> WidgetEntry {
|
||
WidgetEntry(
|
||
date: Date(),
|
||
configuration: ConfigurationAppIntent(),
|
||
completionRate: completionRate,
|
||
currentStreak: streak,
|
||
nextHabits: habits,
|
||
weeklyTrend: [],
|
||
currentTimeOfDay: timeOfDay,
|
||
currentTimeOfDaySymbol: symbol,
|
||
currentTimeOfDayRange: range,
|
||
nextRitualInfo: nextRitual
|
||
)
|
||
}
|
||
|
||
/// Preview entries for each time of day
|
||
static let morningPreview = WidgetEntry.preview(
|
||
timeOfDay: "Morning",
|
||
symbol: "sunrise.fill",
|
||
range: "Before 11am",
|
||
habits: [
|
||
HabitEntry(id: UUID(), title: "Morning Meditation", symbolName: "figure.mind.and.body", ritualTitle: "Mindfulness", isCompleted: false),
|
||
HabitEntry(id: UUID(), title: "Drink Water", symbolName: "drop.fill", ritualTitle: "Health", isCompleted: true),
|
||
HabitEntry(id: UUID(), title: "Take Vitamins", symbolName: "pill.fill", ritualTitle: "Health", isCompleted: false)
|
||
],
|
||
nextRitual: "Next: Midday Movement (11am – 2pm)"
|
||
)
|
||
|
||
static let middayPreview = WidgetEntry.preview(
|
||
timeOfDay: "Midday",
|
||
symbol: "sun.max.fill",
|
||
range: "11am – 2pm",
|
||
habits: [
|
||
HabitEntry(id: UUID(), title: "Midday Walk", symbolName: "figure.walk", ritualTitle: "Movement", isCompleted: false),
|
||
HabitEntry(id: UUID(), title: "Stretch Break", symbolName: "figure.flexibility", ritualTitle: "Movement", isCompleted: false)
|
||
],
|
||
nextRitual: "Next: Deep Work (2pm – 5pm)"
|
||
)
|
||
|
||
static let afternoonPreview = WidgetEntry.preview(
|
||
timeOfDay: "Afternoon",
|
||
symbol: "sun.haze.fill",
|
||
range: "2pm – 5pm",
|
||
habits: [
|
||
HabitEntry(id: UUID(), title: "Deep Focus Block", symbolName: "brain", ritualTitle: "Productivity", isCompleted: true),
|
||
HabitEntry(id: UUID(), title: "Clear Inbox", symbolName: "envelope.fill", ritualTitle: "Productivity", isCompleted: false)
|
||
],
|
||
nextRitual: "Next: Evening Wind-Down (5pm – 9pm)"
|
||
)
|
||
|
||
static let eveningPreview = WidgetEntry.preview(
|
||
timeOfDay: "Evening",
|
||
symbol: "sunset.fill",
|
||
range: "5pm – 9pm",
|
||
habits: [
|
||
HabitEntry(id: UUID(), title: "Evening Reflection", symbolName: "book.fill", ritualTitle: "Mindfulness", isCompleted: false),
|
||
HabitEntry(id: UUID(), title: "Gratitude Journal", symbolName: "heart.text.square.fill", ritualTitle: "Mindfulness", isCompleted: false)
|
||
],
|
||
nextRitual: "Next: Sleep Prep (After 9pm)"
|
||
)
|
||
|
||
static let nightPreview = WidgetEntry.preview(
|
||
timeOfDay: "Night",
|
||
symbol: "moon.stars.fill",
|
||
range: "After 9pm",
|
||
habits: [
|
||
HabitEntry(id: UUID(), title: "No Screens", symbolName: "iphone.slash", ritualTitle: "Sleep Prep", isCompleted: false),
|
||
HabitEntry(id: UUID(), title: "Read Book", symbolName: "book.closed.fill", ritualTitle: "Sleep Prep", isCompleted: false)
|
||
],
|
||
nextRitual: "Next: Morning Routine (Tomorrow)"
|
||
)
|
||
|
||
static let emptyPreview = WidgetEntry.preview(
|
||
timeOfDay: "Afternoon",
|
||
symbol: "sun.haze.fill",
|
||
range: "2pm – 5pm",
|
||
habits: [],
|
||
nextRitual: "Next: Evening Wind-Down (5pm – 9pm)"
|
||
)
|
||
}
|