Skip to content

Commit 2e566bb

Browse files
author
Reed Es
committed
Refactored 'today' view to consolidate
1 parent 861dc67 commit 2e566bb

File tree

4 files changed

+83
-73
lines changed

4 files changed

+83
-73
lines changed

Daily Calorie Tracker Watch.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
402CF94329BBF62D00129305 /* TodayDayRun.swift in Sources */ = {isa = PBXBuildFile; fileRef = 402CF94229BBF62D00129305 /* TodayDayRun.swift */; };
1110
402CF94529BC33FB00129305 /* ServingRunDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 402CF94429BC33FB00129305 /* ServingRunDetail.swift */; };
1211
4037309A29A8259900DB910E /* ServingRunList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4037309929A8259900DB910E /* ServingRunList.swift */; };
12+
40822B9E29C75FCF001C688D /* WatchTodayDayRun.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40822B9D29C75FCF001C688D /* WatchTodayDayRun.swift */; };
1313
409EF4A9298F3EAF0050B99D /* Daily Calorie Tracker.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 409EF4A8298F3EAF0050B99D /* Daily Calorie Tracker.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
1414
409EF4AE298F3EAF0050B99D /* WatchApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 409EF4AD298F3EAF0050B99D /* WatchApp.swift */; };
1515
409EF4B0298F3EAF0050B99D /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 409EF4AF298F3EAF0050B99D /* ContentView.swift */; };
@@ -46,9 +46,9 @@
4646
/* Begin PBXFileReference section */
4747
40098544298F5492008565F3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4848
40098545298F54A1008565F3 /* App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = App.entitlements; sourceTree = "<group>"; };
49-
402CF94229BBF62D00129305 /* TodayDayRun.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayDayRun.swift; sourceTree = "<group>"; };
5049
402CF94429BC33FB00129305 /* ServingRunDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServingRunDetail.swift; sourceTree = "<group>"; };
5150
4037309929A8259900DB910E /* ServingRunList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServingRunList.swift; sourceTree = "<group>"; };
51+
40822B9D29C75FCF001C688D /* WatchTodayDayRun.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchTodayDayRun.swift; sourceTree = "<group>"; };
5252
409EF4A2298F3EAF0050B99D /* Daily Calorie Tracker Watch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Daily Calorie Tracker Watch.app"; sourceTree = BUILT_PRODUCTS_DIR; };
5353
409EF4A8298F3EAF0050B99D /* Daily Calorie Tracker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Daily Calorie Tracker.app"; sourceTree = BUILT_PRODUCTS_DIR; };
5454
409EF4AD298F3EAF0050B99D /* WatchApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchApp.swift; sourceTree = "<group>"; };
@@ -106,7 +106,7 @@
106106
409EF4AF298F3EAF0050B99D /* ContentView.swift */,
107107
4037309929A8259900DB910E /* ServingRunList.swift */,
108108
402CF94429BC33FB00129305 /* ServingRunDetail.swift */,
109-
402CF94229BBF62D00129305 /* TodayDayRun.swift */,
109+
40822B9D29C75FCF001C688D /* WatchTodayDayRun.swift */,
110110
40098545298F54A1008565F3 /* App.entitlements */,
111111
409EF4B1298F3EB00050B99D /* Assets.xcassets */,
112112
40098544298F5492008565F3 /* Info.plist */,
@@ -229,10 +229,10 @@
229229
buildActionMask = 2147483647;
230230
files = (
231231
402CF94529BC33FB00129305 /* ServingRunDetail.swift in Sources */,
232-
402CF94329BBF62D00129305 /* TodayDayRun.swift in Sources */,
233232
409EF4B0298F3EAF0050B99D /* ContentView.swift in Sources */,
234233
409EF4AE298F3EAF0050B99D /* WatchApp.swift in Sources */,
235234
4037309A29A8259900DB910E /* ServingRunList.swift in Sources */,
235+
40822B9E29C75FCF001C688D /* WatchTodayDayRun.swift in Sources */,
236236
);
237237
runOnlyForDeploymentPostprocessing = 0;
238238
};

Sources/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct ContentView: View {
3838
private func destination(_ router: DcaltRouter, _ route: DcaltRoute) -> some View {
3939
switch route {
4040
case .dayRunToday:
41-
TodayDayRun()
41+
WatchTodayDayRun()
4242
.environmentObject(router)
4343
.environment(\.managedObjectContext, viewContext)
4444
case let .servingRunDetail(servingRunUri):

Sources/TodayDayRun.swift

Lines changed: 0 additions & 68 deletions
This file was deleted.

Sources/WatchTodayDayRun.swift

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)