forked from pointfreeco/sqlite-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.swift
More file actions
82 lines (72 loc) · 1.84 KB
/
App.swift
File metadata and controls
82 lines (72 loc) · 1.84 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import CasePaths
import SQLiteData
import SwiftUI
@MainActor
@Observable
class AppModel {
var path: [Path] {
didSet { bind() }
}
var syncUpsList: SyncUpsListModel {
didSet { bind() }
}
@ObservationIgnored
@Dependency(\.date.now) var now
@ObservationIgnored
@Dependency(\.uuid) var uuid
@CasePathable
@dynamicMemberLookup
enum Path: Hashable {
case detail(SyncUpDetailModel)
case meeting(Meeting, attendees: [Attendee])
case record(RecordMeetingModel)
}
init(
path: [Path] = [],
syncUpsList: SyncUpsListModel = SyncUpsListModel()
) {
self.path = path
self.syncUpsList = syncUpsList
self.bind()
}
private func bind() {
for destination in path {
switch destination {
case let .detail(detailModel):
bindDetail(model: detailModel)
case .meeting, .record:
break
}
}
}
private func bindDetail(model: SyncUpDetailModel) {
model.onMeetingStarted = { [weak self] syncUp, attendees in
guard let self else { return }
withDependencies(from: self) {
path.append(.record(RecordMeetingModel(syncUp: syncUp, attendees: attendees)))
}
}
}
}
struct AppView: View {
@Bindable var model: AppModel
var body: some View {
NavigationStack(path: $model.path) {
SyncUpsList(model: model.syncUpsList)
.navigationDestination(for: AppModel.Path.self) { path in
switch path {
case let .detail(model):
SyncUpDetailView(model: model)
case let .meeting(meeting, attendees: attendees):
MeetingView(meeting: meeting, attendees: attendees)
case let .record(model):
RecordMeetingView(model: model)
}
}
}
}
}
#Preview("Happy path") {
let _ = try! prepareDependencies { try $0.bootstrapDatabase() }
AppView(model: AppModel())
}