Glimmer / app · glimmertoday.ai / native / Glimmer / Seasonal.swift
| 1 | import SwiftUI |
| 2 | |
| 3 | struct SeasonalView: View { |
| 4 | @Environment(JournalStore.self) private var store |
| 5 | @Environment(\.readingTheme) private var theme |
| 6 | @Environment(\.dynamicTypeSize) private var typeSize |
| 7 | @State private var selectedEdition: String? |
| 8 | |
| 9 | private var edition: SeasonalEdition? { |
| 10 | let editions = store.seasonalEditions |
| 11 | return editions.first { $0.id == selectedEdition } |
| 12 | ?? editions.first { $0.isFeatured(on: store.day) } |
| 13 | ?? editions.first |
| 14 | } |
| 15 | |
| 16 | var body: some View { |
| 17 | GeometryReader { viewport in |
| 18 | let wide = viewport.size.width >= 650 && !typeSize.isAccessibilitySize |
| 19 | ScrollView { |
| 20 | VStack(alignment: .leading, spacing: 22) { |
| 21 | if let edition { |
| 22 | if store.seasonalEditions.count > 1 { |
| 23 | Picker("Season", selection: Binding( |
| 24 | get: { selectedEdition ?? edition.id }, |
| 25 | set: { selectedEdition = $0 } |
| 26 | )) { |
| 27 | ForEach(store.seasonalEditions) { Text($0.title).tag($0.id) } |
| 28 | } |
| 29 | .pickerStyle(.menu) |
| 30 | } |
| 31 | header(edition) |
| 32 | editionContent(edition, wide: wide) |
| 33 | .id(edition.id) |
| 34 | } else { |
| 35 | Text("Seasonal guides will appear here as they’re added.") |
| 36 | NavigationLink("Cleaning & maintenance") { |
| 37 | if let catalog = store.catalog { CleaningView(catalog: catalog) } |
| 38 | } |
| 39 | .glimmerButton() |
| 40 | } |
| 41 | } |
| 42 | .frame(maxWidth: 880, alignment: .leading) |
| 43 | .padding(.horizontal, 20) |
| 44 | .padding(.top, 16) |
| 45 | .padding(.bottom, 32) |
| 46 | .frame(maxWidth: .infinity) |
| 47 | } |
| 48 | } |
| 49 | .navigationTitle("Seasonal") |
| 50 | #if os(iOS) |
| 51 | .navigationBarTitleDisplayMode(.inline) |
| 52 | #endif |
| 53 | .background { PageBackdrop() } |
| 54 | .tint(GlimmerColor.accent) |
| 55 | } |
| 56 | |
| 57 | private func header(_ edition: SeasonalEdition) -> some View { |
| 58 | VStack(alignment: .leading, spacing: 7) { |
| 59 | Text(edition.title) |
| 60 | .font(GlimmerFont.reading(.largeTitle, weight: .medium)) |
| 61 | .accessibilityAddTraits(.isHeader) |
| 62 | Text(edition.summary) |
| 63 | .font(.callout) |
| 64 | .foregroundStyle(.secondary) |
| 65 | .fixedSize(horizontal: false, vertical: true) |
| 66 | } |
| 67 | .frame(maxWidth: .infinity, alignment: .leading) |
| 68 | .padding(.horizontal, 20) |
| 69 | .padding(.vertical, 16) |
| 70 | .background { |
| 71 | RoundedRectangle(cornerRadius: 14) |
| 72 | .fill(theme.inset.opacity(theme == .glimmer ? 0.67 : 0.58)) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | private func editionContent(_ edition: SeasonalEdition, wide: Bool) -> some View { |
| 77 | let columns = wide ? AnyLayout(HStackLayout(alignment: .top, spacing: 16)) |
| 78 | : AnyLayout(VStackLayout(alignment: .leading, spacing: 20)) |
| 79 | return VStack(alignment: .leading, spacing: 20) { |
| 80 | reflections(edition, wide: wide) |
| 81 | columns { |
| 82 | checklists(edition).frame(maxWidth: .infinity, alignment: .topLeading) |
| 83 | upkeep(edition).frame(maxWidth: .infinity, alignment: .topLeading) |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | private func reflections(_ edition: SeasonalEdition, wide: Bool) -> some View { |
| 89 | let layout = wide ? AnyLayout(HStackLayout(alignment: .top, spacing: 10)) |
| 90 | : AnyLayout(VStackLayout(spacing: 8)) |
| 91 | return VStack(alignment: .leading, spacing: 9) { |
| 92 | heading("For now", icon: "sparkle", tint: GlimmerColor.ember) |
| 93 | layout { |
| 94 | ForEach(edition.tips) { tip in reflection(tip, wide: wide) } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | private func reflection(_ tip: SeasonalEdition.Tip, wide: Bool) -> some View { |
| 100 | NavigationLink { |
| 101 | Page(title: tip.title, width: 660) { |
| 102 | Text(tip.body) |
| 103 | .font(GlimmerFont.reading(.title3)) |
| 104 | .lineSpacing(5) |
| 105 | .fixedSize(horizontal: false, vertical: true) |
| 106 | } |
| 107 | } label: { |
| 108 | HStack(alignment: .top, spacing: 10) { |
| 109 | GlyphTile(reflectionIcon(tip.id), tint: GlimmerColor.ember) |
| 110 | VStack(alignment: .leading, spacing: 5) { |
| 111 | Text(tip.title).font(.callout.weight(.semibold)) |
| 112 | Text(tip.summary).font(.caption).foregroundStyle(.secondary) |
| 113 | } |
| 114 | .fixedSize(horizontal: false, vertical: true) |
| 115 | Spacer(minLength: 0) |
| 116 | Image(systemName: "chevron.right") |
| 117 | .font(.caption2.weight(.semibold)) |
| 118 | .foregroundStyle(.tertiary) |
| 119 | .accessibilityHidden(true) |
| 120 | } |
| 121 | .padding(11) |
| 122 | .frame(maxWidth: .infinity, minHeight: wide ? 96 : 70, alignment: .topLeading) |
| 123 | .seasonalSurface(theme) |
| 124 | .contentShape(.rect) |
| 125 | } |
| 126 | .buttonStyle(.plain) |
| 127 | .accessibilityIdentifier("seasonal.tip." + tip.id) |
| 128 | } |
| 129 | |
| 130 | private func checklists(_ edition: SeasonalEdition) -> some View { |
| 131 | VStack(alignment: .leading, spacing: 9) { |
| 132 | heading("Short checklists", icon: "checklist", tint: GlimmerColor.sage) |
| 133 | VStack(alignment: .leading, spacing: 0) { |
| 134 | ForEach(edition.checklists) { list in |
| 135 | SeasonalChecklist(list: list, progressKey: edition.progressKey(for: list, on: store.day)) |
| 136 | if list.id != edition.checklists.last?.id { Divider().accessibilityHidden(true) } |
| 137 | } |
| 138 | } |
| 139 | .padding(.horizontal, 10) |
| 140 | .seasonalSurface(theme) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | @ViewBuilder private func upkeep(_ edition: SeasonalEdition) -> some View { |
| 145 | let chores = edition.maintenance.compactMap { id in store.maintenanceChores.first { $0.id == id } } |
| 146 | if !chores.isEmpty { |
| 147 | VStack(alignment: .leading, spacing: 9) { |
| 148 | heading("Around the house", icon: "house", tint: GlimmerColor.dusk) |
| 149 | VStack(alignment: .leading, spacing: 10) { |
| 150 | MaintenanceChores(chores: chores, compact: true) |
| 151 | ForEach(edition.resources ?? []) { resource in |
| 152 | Link(destination: resource.url) { |
| 153 | Label(resource.title, systemImage: "arrow.up.right") |
| 154 | .font(.caption.weight(.medium)) |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | .padding(11) |
| 159 | .seasonalSurface(theme) |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | private func reflectionIcon(_ id: String) -> String { |
| 165 | switch id { |
| 166 | case "mixed-feelings": "circle.lefthalf.filled" |
| 167 | case "threshold-pause": "door.left.hand.open" |
| 168 | case "remember-someone": "flame" |
| 169 | default: "lightbulb" |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | private func heading(_ title: String, icon: String, tint: Color) -> some View { |
| 174 | Label { |
| 175 | Text(title).font(.subheadline.weight(.semibold)) |
| 176 | } icon: { |
| 177 | Image(systemName: icon).foregroundStyle(tint) |
| 178 | } |
| 179 | .accessibilityAddTraits(.isHeader) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | private extension View { |
| 184 | func seasonalSurface(_ theme: ReadingTheme) -> some View { |
| 185 | background { |
| 186 | RoundedRectangle(cornerRadius: 12).fill(theme.surface) |
| 187 | .overlay { |
| 188 | RoundedRectangle(cornerRadius: 12).strokeBorder(.primary.opacity(0.10), lineWidth: 0.5) |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | private struct SeasonalChecklist: View { |
| 195 | @Environment(JournalStore.self) private var store |
| 196 | @Environment(\.accessibilityReduceMotion) private var reduceMotion |
| 197 | @State private var expanded = false |
| 198 | let list: SeasonalEdition.Checklist |
| 199 | let progressKey: String |
| 200 | |
| 201 | var body: some View { |
| 202 | let saved = store.journal.seasonalChecks?[progressKey] ?? [] |
| 203 | let complete = list.items.filter { saved.contains($0.id) }.count |
| 204 | VStack(alignment: .leading, spacing: 4) { |
| 205 | Button { |
| 206 | expanded.toggle() |
| 207 | } label: { |
| 208 | HStack(spacing: 9) { |
| 209 | GlyphTile(icon, tint: GlimmerColor.sage) |
| 210 | VStack(alignment: .leading, spacing: 4) { |
| 211 | Text(list.title).font(.callout.weight(.semibold)) |
| 212 | if !expanded { Text(list.summary).font(.caption).foregroundStyle(.secondary) } |
| 213 | } |
| 214 | .fixedSize(horizontal: false, vertical: true) |
| 215 | Spacer(minLength: 4) |
| 216 | progressRing(complete) |
| 217 | Image(systemName: "chevron.right") |
| 218 | .rotationEffect(.degrees(expanded ? 90 : 0)) |
| 219 | .animation(reduceMotion ? nil : .smooth(duration: 0.22), value: expanded) |
| 220 | .font(.caption2.weight(.semibold)) |
| 221 | .foregroundStyle(.tertiary) |
| 222 | .accessibilityHidden(true) |
| 223 | } |
| 224 | .padding(.vertical, 7) |
| 225 | .frame(minHeight: 48) |
| 226 | .contentShape(.rect) |
| 227 | } |
| 228 | .buttonStyle(.plain) |
| 229 | .accessibilityElement(children: .combine) |
| 230 | .accessibilityValue("\(complete) of \(list.items.count) done") |
| 231 | .accessibilityIdentifier("seasonal.list." + list.id) |
| 232 | .accessibilityHint(expanded ? "Collapse checklist" : "Expand checklist") |
| 233 | |
| 234 | ReadingDisclosure(expanded: expanded) { visible in |
| 235 | VStack(spacing: 4) { |
| 236 | ForEach(Array(list.items.enumerated()), id: \.element.id) { index, item in |
| 237 | itemRow(item, checked: saved.contains(item.id)) |
| 238 | .modifier(DisclosureRowMotion(index: index, count: list.items.count, visible: visible)) |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | private var icon: String { |
| 246 | switch list.id { |
| 247 | case "make-room": "calendar.badge.clock" |
| 248 | case "changing-routines": "suitcase" |
| 249 | case "gentler-day": "cup.and.saucer" |
| 250 | default: "checklist" |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | private func progressRing(_ complete: Int) -> some View { |
| 255 | let fraction = Double(complete) / Double(max(1, list.items.count)) |
| 256 | return HStack(spacing: 4) { |
| 257 | ZStack { |
| 258 | Circle().strokeBorder(.secondary.opacity(0.28), lineWidth: 1.5) |
| 259 | Circle().trim(from: 0, to: fraction) |
| 260 | .stroke(GlimmerColor.sage, style: StrokeStyle(lineWidth: 1.75, lineCap: .round)) |
| 261 | .rotationEffect(.degrees(-90)) |
| 262 | } |
| 263 | .frame(width: 14, height: 14) |
| 264 | Text("\(complete)/\(list.items.count)") |
| 265 | .font(.caption2.monospacedDigit()) |
| 266 | .foregroundStyle(.secondary) |
| 267 | .fixedSize() |
| 268 | } |
| 269 | .accessibilityHidden(true) |
| 270 | } |
| 271 | |
| 272 | private func itemRow(_ item: SeasonalEdition.Checklist.Item, checked: Bool) -> some View { |
| 273 | Button { |
| 274 | store.change { $0.toggleSeasonalCheck(item.id, in: progressKey) } |
| 275 | } label: { |
| 276 | HStack(alignment: .top, spacing: 10) { |
| 277 | Tick(done: checked, size: 24) |
| 278 | GlyphTile(Glyph.symbol(name: item.title, category: "seasonal"), tint: Glyph.tint(for: "seasonal")) |
| 279 | VStack(alignment: .leading, spacing: 4) { |
| 280 | Text(item.title).font(.body.weight(.medium)) |
| 281 | .foregroundStyle(checked ? Color.secondary : Color.primary) |
| 282 | Text(item.detail).font(.callout).foregroundStyle(.secondary) |
| 283 | } |
| 284 | .fixedSize(horizontal: false, vertical: true) |
| 285 | } |
| 286 | .padding(.horizontal, 5).padding(.vertical, 7) |
| 287 | .frame(maxWidth: .infinity, minHeight: 44, alignment: .leading) |
| 288 | .contentShape(.rect) |
| 289 | } |
| 290 | .buttonStyle(RowPressStyle()) |
| 291 | .tickFeedback(checked) |
| 292 | .accessibilityElement(children: .combine) |
| 293 | .accessibilityAddTraits(checked ? .isSelected : []) |
| 294 | .accessibilityValue(checked ? "Completed" : "Not completed") |
| 295 | .accessibilityIdentifier("seasonal.check." + item.id) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | struct SeasonalRecommendation: View { |
| 300 | @Environment(JournalStore.self) private var store |
| 301 | let edition: SeasonalEdition |
| 302 | let list: SeasonalEdition.Checklist |
| 303 | let item: SeasonalEdition.Checklist.Item |
| 304 | let showGuide: () -> Void |
| 305 | |
| 306 | var body: some View { |
| 307 | let key = edition.progressKey(for: list, on: store.day) |
| 308 | let checked = store.journal.seasonalChecks?[key]?.contains(item.id) == true |
| 309 | VStack(alignment: .leading, spacing: 4) { |
| 310 | Label(edition.title, systemImage: Destination.seasonal.icon) |
| 311 | .font(.caption.weight(.semibold)) |
| 312 | .foregroundStyle(GlimmerColor.honey) |
| 313 | .accessibilityAddTraits(.isHeader) |
| 314 | Button { |
| 315 | store.change { $0.toggleSeasonalCheck(item.id, in: key) } |
| 316 | } label: { |
| 317 | HStack(spacing: 10) { |
| 318 | Tick(done: checked, size: 22) |
| 319 | Text(item.title) |
| 320 | .font(.callout.weight(.semibold)) |
| 321 | .foregroundStyle(checked ? .secondary : .primary) |
| 322 | .multilineTextAlignment(.leading) |
| 323 | .fixedSize(horizontal: false, vertical: true) |
| 324 | } |
| 325 | .frame(maxWidth: .infinity, minHeight: 44, alignment: .leading) |
| 326 | .contentShape(.rect) |
| 327 | } |
| 328 | .buttonStyle(RowPressStyle()) |
| 329 | .tickFeedback(checked) |
| 330 | .accessibilityValue(checked ? "Completed" : "Not completed") |
| 331 | .accessibilityIdentifier("today.seasonal.check") |
| 332 | |
| 333 | if !checked, !item.detail.isEmpty { |
| 334 | Text(item.detail) |
| 335 | .font(.callout) |
| 336 | .foregroundStyle(.secondary) |
| 337 | .fixedSize(horizontal: false, vertical: true) |
| 338 | .padding(.leading, 22) |
| 339 | } |
| 340 | |
| 341 | Button(action: showGuide) { |
| 342 | Text("See seasonal guide") |
| 343 | .font(.callout.weight(.medium)) |
| 344 | .frame(minHeight: 44, alignment: .leading) |
| 345 | .padding(.leading, 22) |
| 346 | } |
| 347 | .buttonStyle(.plain) |
| 348 | .foregroundStyle(GlimmerColor.accent) |
| 349 | .accessibilityIdentifier("today.seasonal") |
| 350 | } |
| 351 | .padding(.horizontal, 14) |
| 352 | .padding(.vertical, 9) |
| 353 | .frame(maxWidth: .infinity, alignment: .leading) |
| 354 | .overlay { |
| 355 | RoundedRectangle(cornerRadius: 13).strokeBorder(GlimmerColor.honey.opacity(0.32)) |
| 356 | .allowsHitTesting(false) |
| 357 | } |
| 358 | } |
| 359 | } |