|
| 1 | +// |
| 2 | +// WatchTodayDayRun.swift |
| 3 | +// |
| 4 | +// Copyright 2023 OpenAlloc LLC |
| 5 | +// |
| 6 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | +// |
| 10 | + |
| 11 | +import CoreData |
| 12 | +import os |
| 13 | +import SwiftUI |
| 14 | + |
| 15 | +import DcaltLib |
| 16 | +import DcaltUI |
| 17 | +import TrackerUI |
| 18 | + |
| 19 | +import SwiftUI |
| 20 | + |
| 21 | +struct WatchTodayDayRun: View { |
| 22 | + @Environment(\.managedObjectContext) private var viewContext |
| 23 | + @EnvironmentObject private var router: DcaltRouter |
| 24 | + @EnvironmentObject private var manager: CoreDataStack |
| 25 | + |
| 26 | +// private static let df: DateFormatter = { |
| 27 | +// let df = DateFormatter() |
| 28 | +// df.dateStyle = .medium |
| 29 | +// df.timeStyle = .none |
| 30 | +// return df |
| 31 | +// }() |
| 32 | + |
| 33 | + var body: some View { |
| 34 | + VStack { |
| 35 | + if let mainStore = manager.getMainStore(viewContext) { |
| 36 | + TodayDayRun(mainStore: mainStore) { zDayRun, _ in |
| 37 | + ServingRunList(zDayRun: zDayRun, mainStore: mainStore) |
| 38 | + // .navigationTitle(Self.df.string(from: dateVal)) |
| 39 | + } |
| 40 | + } else { |
| 41 | + Text("Recent data not available.") |
| 42 | + } |
| 43 | + } |
| 44 | + .navigationTitle("Today") |
| 45 | + .navigationBarTitleDisplayMode(.inline) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +struct WatchTodayDayRun_Previews: PreviewProvider { |
| 50 | + static var previews: some View { |
| 51 | + let manager = CoreDataStack.getPreviewStack() |
| 52 | + let ctx = manager.container.viewContext |
| 53 | + let store = manager.getMainStore(ctx)! |
| 54 | + |
| 55 | + let consumedDay1 = "2023-02-01" |
| 56 | + let consumedTime1 = "16:05" |
| 57 | + |
| 58 | + let category1ArchiveID = UUID() |
| 59 | + let category2ArchiveID = UUID() |
| 60 | + let serving1ArchiveID = UUID() |
| 61 | + let serving2ArchiveID = UUID() |
| 62 | + |
| 63 | + let zc1 = ZCategory.create(ctx, categoryArchiveID: category1ArchiveID, categoryName: "Fruit", toStore: store) |
| 64 | + let zc2 = ZCategory.create(ctx, categoryArchiveID: category2ArchiveID, categoryName: "Meat", toStore: store) |
| 65 | + let zs1 = ZServing.create(ctx, zCategory: zc1, servingArchiveID: serving1ArchiveID, servingName: "Banana and Peaches and Pears and whatnot", toStore: store) |
| 66 | + let zs2 = ZServing.create(ctx, zCategory: zc2, servingArchiveID: serving2ArchiveID, servingName: "Steak and fritos and kiwis", toStore: store) |
| 67 | + let zdr = ZDayRun.create(ctx, consumedDay: consumedDay1, calories: 2433, toStore: store) |
| 68 | + _ = ZServingRun.create(ctx, zDayRun: zdr, zServing: zs1, consumedTime: consumedTime1, calories: 2120, toStore: store) |
| 69 | + _ = ZServingRun.create(ctx, zDayRun: zdr, zServing: zs2, consumedTime: consumedTime1, calories: 6450, toStore: store) |
| 70 | + try? ctx.save() |
| 71 | + |
| 72 | + return NavigationStack { |
| 73 | + WatchTodayDayRun() |
| 74 | + } |
| 75 | + .environment(\.managedObjectContext, ctx) |
| 76 | + .environmentObject(manager) |
| 77 | + } |
| 78 | +} |
0 commit comments