DayByDay/DaysOfWeekView.swift
29 lines · 862 bytes
2 symbols in this file
1//
2// DaysOfWeekView.swift
3// DayByDay
4//
5
6import SwiftData
7import SwiftUI
8
9/// Displays all seven days of the week as large, tappable cards in a scrollable grid.
10/// Adapts between 1 and 2 columns depending on available width.
11struct DaysOfWeekView: View {
12 @Environment(ProfileSession.self) private var session
13
14 var body: some View {
15 CardGrid(items: DayOfWeek.allCases) { day in
16 DayCard(day: day, isHighlighted: day == .current, picture: picture(on: day))
17 }
18 .onDisappear { CardVoice.shared.cancel() }
19 }
20
21 private func picture(on day: DayOfWeek) -> DayPictureKind? {
22 session.current.flatMap { session.store.picture(on: day, for: $0) }
23 }
24}
25
26#Preview {
27 DaysOfWeekView()
28 .environment(ProfileSession(store: ProfileStore(context: ProfileStore.makeContainer(inMemory: true).mainContext)))
29}