-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeView.swift
executable file
·97 lines (86 loc) · 3.06 KB
/
HomeView.swift
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// HomeView.swift
// PainMedsBuddy
//
// Created by Jules Moorhouse.
//
// INFO: This view shows a summary on medication which has or can be taken next
import CircularProgress
import CoreData
import SwiftUI
struct HomeView: View {
static let homeTag: String? = "Home"
static let homeIcon: String = SFSymbol.house.systemName
@StateObject private var viewModel: ViewModel
@EnvironmentObject private var presentableToast: PresentableToastModel
var columns: [GridItem] {
[GridItem(.fixed(200))]
}
var noData: Bool {
viewModel.reaffirmedDoses.isEmpty &&
viewModel.lowMeds.isEmpty &&
viewModel.recentMeds.isEmpty
}
var currentMedCards: some View {
ScrollView(.horizontal, showsIndicators: false) {
LazyHGrid(rows: columns) {
if !viewModel.reaffirmedDoses.isEmpty {
ForEach(viewModel.reaffirmedDoses, id: \.self) { item in
if let med = item.med {
HomeDoseProgressView(
dose: item,
med: med
)
}
}
} else {
HomeDoseProgressView(disabled: true)
}
}
.fixedSize(horizontal: false, vertical: true)
.padding([.horizontal, .bottom])
.accessibilityIdentifier(.homeCurrentMeds)
}
}
var body: some View {
NavigationViewChild {
Group {
if noData {
PlaceholderView(
string: .commonEmptyView,
imageString: HomeView.homeIcon
)
} else {
ScrollView {
VStack(alignment: .leading) {
HomeHeadingView(.homeCurrentMeds)
.padding([.leading, .trailing])
currentMedCards
VStack(alignment: .leading) {
HomeRecentMedsView(meds: viewModel.recentMeds)
HomeLowMedsView(meds: viewModel.lowMeds)
}
.padding(.horizontal)
}
}
}
}
.background(!noData ? Color.systemGroupedBackground.ignoresSafeArea() : nil)
.toasted(show: $presentableToast.show, data: $presentableToast.data)
.navigationTitle(Strings.commonAppName.rawValue)
.navigationBarAccessibilityIdentifier(.commonAppName)
}
.onAppear(perform: {
RequestReview.showReview()
})
}
init(dataController: DataController) {
let viewModel = ViewModel(dataController: dataController)
_viewModel = StateObject(wrappedValue: viewModel)
}
}
struct HomeView_Previews: PreviewProvider {
static var previews: some View {
HomeView(dataController: .preview)
}
}