-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentView.swift
80 lines (70 loc) · 2.62 KB
/
ContentView.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
//
// ContentView.swift
// ExpenseTracker
//
// Created by ojohnpepsi on 2023-11-08.
//
import SwiftUI
import SwiftUICharts
struct ContentView: View {
@EnvironmentObject var transactionListVM: TransactionListViewModel
// var demoData: [Double] = [8, 2, 4, 6, 12, 9, 2]
var body: some View {
NavigationView {
ScrollView {
VStack(alignment: .leading, spacing: 24) {
// MARK: Title
Text("Overview")
.font(.title2)
.bold()
// MARK: Chart
let data = transactionListVM.accumulateTransactions()
if !data.isEmpty {
let totalExpenses = data.last?.1 ?? 0
CardView {
VStack(alignment: .leading) {
ChartLabel(totalExpenses.formatted(.currency(code: "CAD")), type: .title, format: "$%.02f")
LineChart()
}
.background(Color.systemBackground)
}
.data(data)
.chartStyle(ChartStyle(backgroundColor: Color.systemBackground, foregroundColor: ColorGradient(Color.icon.opacity(0.4), Color.icon)))
.frame(height: 300)
}
// MARK: Recent Transacation List
RecentTransactionList()
}
.padding()
.frame(maxWidth: .infinity)
}
.background(Color.background)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
// MARK: notification Icon
ToolbarItem {
Image(systemName: "bell.badge")
.symbolRenderingMode(.palette)
.foregroundStyle(Color.icon, .primary)
}
}
}
.navigationViewStyle(.stack)
.accentColor(.primary)
}
}
struct ContentView_Previews: PreviewProvider {
static let transactionListVM: TransactionListViewModel = {
let transactionListVM = TransactionListViewModel()
transactionListVM.transactions = transactionListPreviewData
return transactionListVM
}()
static var previews: some View {
Group {
ContentView()
ContentView()
.preferredColorScheme(/*@START_MENU_TOKEN@*/.dark/*@END_MENU_TOKEN@*/)
}
.environmentObject(transactionListVM)
}
}