DayByDay/ContentView.swift
148 lines · 4920 bytes
2 symbols in this file
1//
2// ContentView.swift
3// DayByDay
4//
5// Created by cmc on 2026-03-09.
6//
7
8import SwiftData
9import SwiftUI
10
11// MARK: - Category model
12
13nonisolated enum Category: Int, CaseIterable, Identifiable {
14 case today, days, months, seasons, numbers, colors, shapes, animals, alphabet,
15 weather, bodyParts, food
16
17 var id: Int { rawValue }
18
19 var label: String {
20 switch self {
21 case .today: "Today"
22 case .days: "Days"
23 case .months: "Months"
24 case .seasons: "Seasons"
25 case .numbers: "Numbers"
26 case .colors: "Colors"
27 case .shapes: "Shapes"
28 case .animals: "Animals"
29 case .alphabet: "Alphabet"
30 case .weather: "Weather"
31 case .bodyParts: "Body"
32 case .food: "Food"
33 }
34 }
35
36 var symbol: String {
37 switch self {
38 case .today: "sun.horizon.fill"
39 case .days: "calendar"
40 case .months: "calendar.badge.clock"
41 case .seasons: "leaf.fill"
42 case .numbers: "123.rectangle.fill"
43 case .colors: "paintpalette.fill"
44 case .shapes: "pentagon.fill"
45 case .animals: "pawprint.fill"
46 case .alphabet: "abc"
47 case .weather: "cloud.sun.rain.fill"
48 case .bodyParts: "figure.stand"
49 case .food: "carrot.fill"
50 }
51 }
52
53 /// Fixed colors with at least 3:1 contrast against white labels in light and dark mode.
54 var color: Color {
55 switch self {
56 case .today: Color(red: 0.84, green: 0.40, blue: 0.08)
57 case .days: Color(red: 0.0, green: 0.42, blue: 0.85)
58 case .months: Color(red: 0.62, green: 0.22, blue: 0.78)
59 case .seasons: Color(red: 0.18, green: 0.56, blue: 0.28)
60 case .numbers: Color(red: 0.86, green: 0.20, blue: 0.22)
61 case .colors: Color(red: 0.82, green: 0.25, blue: 0.52)
62 case .shapes: Color(red: 0.0, green: 0.53, blue: 0.56)
63 case .animals: Color(red: 0.63, green: 0.40, blue: 0.18)
64 case .alphabet: Color(red: 0.35, green: 0.34, blue: 0.84)
65 case .weather: Color(red: 0.10, green: 0.48, blue: 0.78)
66 case .bodyParts: Color(red: 0.80, green: 0.30, blue: 0.46)
67 case .food: Color(red: 0.80, green: 0.42, blue: 0.08)
68 }
69 }
70
71 /// Whether this tile uses a special gradient background instead of the solid color.
72 var usesGradientBackground: Bool {
73 self == .colors
74 }
75}
76
77// MARK: - Home grid tile
78
79struct CategoryTile: View {
80 let category: Category
81
82 var body: some View {
83 ZStack {
84 if category.usesGradientBackground {
85 RoundedRectangle(cornerRadius: 32, style: .continuous)
86 .fill(
87 LinearGradient(
88 colors: [.red, .orange, .yellow, .green, .blue, .purple],
89 startPoint: .leading,
90 endPoint: .trailing
91 )
92 )
93 .shadow(color: category.color.opacity(0.4), radius: 8, y: 4)
94 } else {
95 RoundedRectangle(cornerRadius: 32, style: .continuous)
96 .fill(category.color)
97 .shadow(color: category.color.opacity(0.4), radius: 8, y: 4)
98 }
99
100 VStack(spacing: 12) {
101 Image(systemName: category.symbol)
102 .font(.system(size: 48))
103 .foregroundStyle(.white)
104 .symbolRenderingMode(.hierarchical)
105
106 Text(category.label)
107 .font(.heading(24))
108 .foregroundStyle(.white)
109 }
110 .padding(12)
111 .shadow(color: category.usesGradientBackground ? .black.opacity(0.6) : .clear, radius: 2)
112 }
113 .accessibilityElement(children: .ignore)
114 .accessibilityLabel(category.label)
115 }
116}
117
118// MARK: - Content view
119
120/// Routes between first-launch setup, the profile picker, and home.
121struct ContentView: View {
122 @Environment(ProfileSession.self) private var session
123 @Environment(\.scenePhase) private var scenePhase
124
125 var body: some View {
126 Group {
127 switch session.screen {
128 case .setup: ProfileSetupView()
129 case .picker: ProfilePickerView()
130 case .home: HomeView()
131 }
132 }
133 .onChange(of: scenePhase) { _, phase in
134 switch phase {
135 case .background: session.didEnterBackground(at: .now)
136 case .active: session.willEnterForeground(at: .now)
137 default: break
138 }
139 }
140 }
141}
142
143#Preview {
144 let container = ProfileStore.makeContainer(inMemory: true)
145 ContentView()
146 .environment(ProfileSession(store: ProfileStore(context: container.mainContext)))
147 .modelContainer(container)
148}