@@ -39,15 +39,18 @@ struct CartView : View {
39
39
/// For more details, refer to: https://skie.touchlab.co/features/flows-in-swiftui
40
40
Observing ( cartViewModel. cartUiState) { cartUIState in
41
41
VStack {
42
- HStack {
43
- let total = cartUIState. totalItemCount
44
- Text ( " Cart has \( total) items " ) . padding ( )
45
- Spacer ( )
46
- }
47
42
CartDetailsView ( cartViewModel: cartViewModel)
48
43
Spacer ( )
49
44
}
50
- . navigationTitle ( " Your Cart " )
45
+ . navigationTitle ( " Cart " )
46
+ . toolbar {
47
+ ToolbarItem ( placement: . navigationBarTrailing) {
48
+ Observing ( cartViewModel. cartUiState) { cartUIState in
49
+ let total = cartUIState. totalItemCount
50
+ Text ( " Cart has \( total) items " )
51
+ }
52
+ }
53
+ }
51
54
}
52
55
}
53
56
}
@@ -63,9 +66,28 @@ struct CartDetailsView: View {
63
66
ScrollView {
64
67
LazyVStack {
65
68
ForEach ( cartUIState. cartDetails, id: \. fruittie. id) { item in
66
- Text ( " \( item. fruittie. name) : \( item. count) " )
69
+ HStack {
70
+ Text ( " \( item. count) x \( item. fruittie. name) " )
71
+ . frame ( maxWidth: . infinity, alignment: . leading)
72
+ Spacer ( )
73
+ Button ( action: {
74
+ self . cartViewModel. decreaseCountClick ( cartItem: item)
75
+ } ) {
76
+ Image ( systemName: " minus.circle.fill " )
77
+ . foregroundColor ( . red)
78
+ }
79
+
80
+ Button ( action: {
81
+ self . cartViewModel. increaseCountClick ( cartItem: item)
82
+ } ) {
83
+ Image ( systemName: " plus.circle.fill " )
84
+ . foregroundColor ( . green)
85
+ }
86
+ }
87
+ . padding ( )
67
88
}
68
89
}
90
+ . animation ( . default, value: cartUIState. cartDetails)
69
91
}
70
92
}
71
93
}
0 commit comments