-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestination.swift
More file actions
66 lines (59 loc) · 2.03 KB
/
Destination.swift
File metadata and controls
66 lines (59 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Destination.swift
//
// Copyright 2023 OpenAlloc LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
import CoreData
import os
import SwiftUI
import TrackerUI
import TroutLib
import TroutUI
// handle routes for iOS-specific views here
struct Destination: View {
@Environment(\.managedObjectContext) private var viewContext
@EnvironmentObject private var router: TroutRouter
@EnvironmentObject private var manager: CoreDataStack
var route: TroutRoute
var body: some View {
switch route {
case .routineRunList:
HistoryView()
.environmentObject(router)
.environment(\.managedObjectContext, viewContext)
case .routineRunRecent:
PlusRecentRoutineRun(withSettings: false)
.environmentObject(router)
.environment(\.managedObjectContext, viewContext)
case let .taskRunList(routineRunUri):
taskRunList(routineRunUri)
.environmentObject(router)
.environment(\.managedObjectContext, viewContext)
default:
TroutDestination(route)
.environmentObject(router)
.environment(\.managedObjectContext, viewContext)
}
}
@ViewBuilder
private func taskRunList(_ routineRunUri: URL) -> some View {
if let zRoutineRun: ZRoutineRun = ZRoutineRun.get(viewContext, forURIRepresentation: routineRunUri),
let archiveStore = manager.getArchiveStore(viewContext),
let title = zRoutineRun.zRoutine?.name
{
TaskRunList(zRoutineRun: zRoutineRun, inStore: archiveStore)
.navigationTitle(title)
} else {
Text("Routine Run not available to display detail.")
}
}
}
struct Destination_Previews: PreviewProvider {
static var previews: some View {
Destination(route: .about)
}
}