Преглед на файлове

Cleaned up a bit and added favorite/found setting logic from buttons

Víctor Hernández преди 4 години
родител
ревизия
ec4418bd4d

+ 12
- 12
Flowerdex/Flowerdex.xcodeproj/project.pbxproj Целия файл

@@ -11,7 +11,7 @@
11 11
 		A51B4F772546674C002AFF05 /* FlowersResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */; };
12 12
 		A51B4F7B25466A75002AFF05 /* flowers.json in Resources */ = {isa = PBXBuildFile; fileRef = A51B4F7A25466A75002AFF05 /* flowers.json */; };
13 13
 		A52FB5C42546C2EA000AD235 /* rawResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = A52FB5C32546C2EA000AD235 /* rawResponse.json */; };
14
-		A5711B8B255CE03000E727BB /* FlowerItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5711B8A255CE03000E727BB /* FlowerItem.swift */; };
14
+		A5711B8B255CE03000E727BB /* Flower.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5711B8A255CE03000E727BB /* Flower.swift */; };
15 15
 		A5711B8E255CE53900E727BB /* DummyData.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5711B8D255CE53900E727BB /* DummyData.swift */; };
16 16
 		A58640BA258F30AD00F626AB /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A58640B9258F30AD00F626AB /* LoginView.swift */; };
17 17
 		A58640BE258F30F200F626AB /* RegisterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A58640BD258F30F200F626AB /* RegisterView.swift */; };
@@ -20,7 +20,7 @@
20 20
 		A59A27452545568A0052319F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A59A27442545568A0052319F /* Assets.xcassets */; };
21 21
 		A59A27482545568A0052319F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A59A27472545568A0052319F /* Preview Assets.xcassets */; };
22 22
 		A5AF3F5C2545FDEB0035AC9A /* FlowerCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5AF3F5B2545FDEB0035AC9A /* FlowerCard.swift */; };
23
-		A5EA2F24258FEC2300699182 /* UserService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F23258FEC2300699182 /* UserService.swift */; };
23
+		A5EA2F24258FEC2300699182 /* AuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F23258FEC2300699182 /* AuthenticationService.swift */; };
24 24
 		A5EA2F28258FEC3D00699182 /* FlowerService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F27258FEC3D00699182 /* FlowerService.swift */; };
25 25
 		A5EA2F2C258FF0BD00699182 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F2B258FF0BD00699182 /* Constants.swift */; };
26 26
 		A5EA2F32258FF58200699182 /* Responses.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EA2F31258FF58200699182 /* Responses.swift */; };
@@ -31,7 +31,7 @@
31 31
 		A5EE38AC257772200014D0BE /* FiltersSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38AB257772200014D0BE /* FiltersSheet.swift */; };
32 32
 		A5EE38B0257818520014D0BE /* FlowersList.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38AF257818520014D0BE /* FlowersList.swift */; };
33 33
 		A5EE38B3257818BE0014D0BE /* StatusIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EE38B2257818BE0014D0BE /* StatusIcons.swift */; };
34
-		A5F0D2FC258F3D2200AF735C /* UserModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F0D2FB258F3D2200AF735C /* UserModel.swift */; };
34
+		A5F0D2FC258F3D2200AF735C /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F0D2FB258F3D2200AF735C /* User.swift */; };
35 35
 		A5F3271A25460C0B003BCE0F /* FlowerDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F3271925460C0B003BCE0F /* FlowerDetailView.swift */; };
36 36
 /* End PBXBuildFile section */
37 37
 
@@ -40,7 +40,7 @@
40 40
 		A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowersResponseModel.swift; sourceTree = "<group>"; };
41 41
 		A51B4F7A25466A75002AFF05 /* flowers.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = flowers.json; sourceTree = "<group>"; };
42 42
 		A52FB5C32546C2EA000AD235 /* rawResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = rawResponse.json; sourceTree = "<group>"; };
43
-		A5711B8A255CE03000E727BB /* FlowerItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerItem.swift; sourceTree = "<group>"; };
43
+		A5711B8A255CE03000E727BB /* Flower.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Flower.swift; sourceTree = "<group>"; };
44 44
 		A5711B8D255CE53900E727BB /* DummyData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DummyData.swift; sourceTree = "<group>"; };
45 45
 		A58640B9258F30AD00F626AB /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
46 46
 		A58640BD258F30F200F626AB /* RegisterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterView.swift; sourceTree = "<group>"; };
@@ -51,7 +51,7 @@
51 51
 		A59A27472545568A0052319F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
52 52
 		A59A27492545568A0052319F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
53 53
 		A5AF3F5B2545FDEB0035AC9A /* FlowerCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerCard.swift; sourceTree = "<group>"; };
54
-		A5EA2F23258FEC2300699182 /* UserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserService.swift; sourceTree = "<group>"; };
54
+		A5EA2F23258FEC2300699182 /* AuthenticationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationService.swift; sourceTree = "<group>"; };
55 55
 		A5EA2F27258FEC3D00699182 /* FlowerService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerService.swift; sourceTree = "<group>"; };
56 56
 		A5EA2F2B258FF0BD00699182 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
57 57
 		A5EA2F31258FF58200699182 /* Responses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Responses.swift; sourceTree = "<group>"; };
@@ -62,7 +62,7 @@
62 62
 		A5EE38AB257772200014D0BE /* FiltersSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FiltersSheet.swift; sourceTree = "<group>"; };
63 63
 		A5EE38AF257818520014D0BE /* FlowersList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowersList.swift; sourceTree = "<group>"; };
64 64
 		A5EE38B2257818BE0014D0BE /* StatusIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusIcons.swift; sourceTree = "<group>"; };
65
-		A5F0D2FB258F3D2200AF735C /* UserModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserModel.swift; sourceTree = "<group>"; };
65
+		A5F0D2FB258F3D2200AF735C /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
66 66
 		A5F3271925460C0B003BCE0F /* FlowerDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerDetailView.swift; sourceTree = "<group>"; };
67 67
 /* End PBXFileReference section */
68 68
 
@@ -81,10 +81,10 @@
81 81
 			isa = PBXGroup;
82 82
 			children = (
83 83
 				A51B4F762546674C002AFF05 /* FlowersResponseModel.swift */,
84
-				A5711B8A255CE03000E727BB /* FlowerItem.swift */,
84
+				A5711B8A255CE03000E727BB /* Flower.swift */,
85 85
 				A5EE3896257658400014D0BE /* Filters.swift */,
86 86
 				A5EE389025763D3A0014D0BE /* AuthenticationModel.swift */,
87
-				A5F0D2FB258F3D2200AF735C /* UserModel.swift */,
87
+				A5F0D2FB258F3D2200AF735C /* User.swift */,
88 88
 			);
89 89
 			path = Model;
90 90
 			sourceTree = "<group>";
@@ -162,7 +162,7 @@
162 162
 			isa = PBXGroup;
163 163
 			children = (
164 164
 				A50EEFCC255D175400545CFE /* ContentDataSource.swift */,
165
-				A5EA2F23258FEC2300699182 /* UserService.swift */,
165
+				A5EA2F23258FEC2300699182 /* AuthenticationService.swift */,
166 166
 				A5EA2F27258FEC3D00699182 /* FlowerService.swift */,
167 167
 				A5EE38A3257700230014D0BE /* ImageManager.swift */,
168 168
 			);
@@ -270,7 +270,7 @@
270 270
 				A5EE38B0257818520014D0BE /* FlowersList.swift in Sources */,
271 271
 				A51B4F772546674C002AFF05 /* FlowersResponseModel.swift in Sources */,
272 272
 				A5EE3897257658400014D0BE /* Filters.swift in Sources */,
273
-				A5711B8B255CE03000E727BB /* FlowerItem.swift in Sources */,
273
+				A5711B8B255CE03000E727BB /* Flower.swift in Sources */,
274 274
 				A59A2741254556880052319F /* FlowerdexApp.swift in Sources */,
275 275
 				A5EA2F32258FF58200699182 /* Responses.swift in Sources */,
276 276
 				A58640BE258F30F200F626AB /* RegisterView.swift in Sources */,
@@ -279,9 +279,9 @@
279 279
 				A58640BA258F30AD00F626AB /* LoginView.swift in Sources */,
280 280
 				A5AF3F5C2545FDEB0035AC9A /* FlowerCard.swift in Sources */,
281 281
 				A5EE38B3257818BE0014D0BE /* StatusIcons.swift in Sources */,
282
-				A5EA2F24258FEC2300699182 /* UserService.swift in Sources */,
282
+				A5EA2F24258FEC2300699182 /* AuthenticationService.swift in Sources */,
283 283
 				A5711B8E255CE53900E727BB /* DummyData.swift in Sources */,
284
-				A5F0D2FC258F3D2200AF735C /* UserModel.swift in Sources */,
284
+				A5F0D2FC258F3D2200AF735C /* User.swift in Sources */,
285 285
 				A5EE38AC257772200014D0BE /* FiltersSheet.swift in Sources */,
286 286
 				A5EA2F28258FEC3D00699182 /* FlowerService.swift in Sources */,
287 287
 			);

Двоични данни
Flowerdex/Flowerdex.xcodeproj/project.xcworkspace/xcuserdata/victor.hernandez.xcuserdatad/UserInterfaceState.xcuserstate Целия файл


Flowerdex/Flowerdex/Model/FlowerItem.swift → Flowerdex/Flowerdex/Model/Flower.swift Целия файл

@@ -1,5 +1,5 @@
1 1
 //
2
-//  FlowerItem.swift
2
+//  Flower.swift
3 3
 //  Flowerdex
4 4
 //
5 5
 //  Created by Víctor A. Hernández on 11/11/20.
@@ -7,7 +7,7 @@
7 7
 
8 8
 import Foundation
9 9
 
10
-struct FlowerItem: Hashable, Codable, Identifiable {
10
+struct Flower: Hashable, Codable, Identifiable {
11 11
     let id: Int
12 12
     let common_name: String?
13 13
     var commonName: String {

+ 1
- 1
Flowerdex/Flowerdex/Model/FlowersResponseModel.swift Целия файл

@@ -8,7 +8,7 @@
8 8
 import Foundation
9 9
 
10 10
 struct FlowersResponseModel: Hashable, Codable {
11
-    let data: [FlowerItem]?
11
+    let data: [Flower]?
12 12
     let links: Dictionary<String, String>?
13 13
     let meta: Dictionary<String, Int>?
14 14
     let error: String?

Flowerdex/Flowerdex/Model/UserModel.swift → Flowerdex/Flowerdex/Model/User.swift Целия файл

@@ -1,5 +1,5 @@
1 1
 //
2
-//  UserModel.swift
2
+//  User.swift
3 3
 //  Flowerdex
4 4
 //
5 5
 //  Created by Víctor A. Hernández on 12/20/20.

+ 1
- 1
Flowerdex/Flowerdex/Resources/DummyData.swift Целия файл

@@ -7,7 +7,7 @@
7 7
 
8 8
 import Foundation
9 9
 
10
-let dummyFlowers: [FlowerItem] = load("flowers.json")
10
+let dummyFlowers: [Flower] = load("flowers.json")
11 11
 
12 12
 func load<T: Decodable>(_ filename: String) -> T {
13 13
     let data: Data

+ 833
- 598
Flowerdex/Flowerdex/Resources/flowers.json
Файловите разлики са ограничени, защото са твърде много
Целия файл


Flowerdex/Flowerdex/Services/UserService.swift → Flowerdex/Flowerdex/Services/AuthenticationService.swift Целия файл

@@ -1,5 +1,5 @@
1 1
 //
2
-//  UserService.swift
2
+//  AuthenticationService.swift
3 3
 //  Flowerdex
4 4
 //
5 5
 //  Created by Víctor A. Hernández on 12/20/20.

+ 1
- 1
Flowerdex/Flowerdex/Services/ContentDataSource.swift Целия файл

@@ -11,7 +11,7 @@ import Combine
11 11
 
12 12
 /*
13 13
 class ContentDataSource: ObservableObject {
14
-  @Published var items = [FlowerItem]() // ListItem
14
+  @Published var items = [Flower]() // ListItem
15 15
   @Published var isLoadingPage = false
16 16
   private var currentPage = 1
17 17
   private var canLoadMorePages = true

+ 81
- 4
Flowerdex/Flowerdex/Services/FlowerService.swift Целия файл

@@ -10,7 +10,7 @@ import Foundation
10 10
 class FlowerService: ObservableObject {
11 11
     
12 12
     @Published var response: Response = .unfetched
13
-    @Published var items = [FlowerItem]()
13
+    @Published var items = [Flower]()
14 14
     
15 15
     
16 16
     private func getQueryParameters(_ filters: Filters) -> [URLQueryItem] {
@@ -47,9 +47,11 @@ class FlowerService: ObservableObject {
47 47
         components.scheme = Constants.Services.apiScheme
48 48
         components.host = Constants.Services.apiHost
49 49
         components.path = apiPath
50
-        components.queryItems = [
51
-            URLQueryItem(name: "user_id", value: "\(User.current.id!)"),
52
-        ]
50
+        if apiPath == Constants.Services.apiGetFlowersPath {
51
+            components.queryItems = [
52
+                URLQueryItem(name: "user_id", value: "\(User.current.id!)"),
53
+            ]
54
+        }
53 55
         return components
54 56
     }
55 57
     
@@ -111,4 +113,79 @@ class FlowerService: ObservableObject {
111 113
         
112 114
     }
113 115
     
116
+    
117
+    func wishlistOrHistorySkeletonRequest(_ flowerID: Int, remove: Bool, wishlist: Bool) {
118
+        
119
+        // Construct Body
120
+        let jsonObject : [String: Int] = [
121
+            "user_id": User.current.id!,
122
+            "flower_id": flowerID
123
+        ]
124
+        
125
+        guard let jsonData = try? JSONEncoder().encode(jsonObject) else {
126
+            print("Failed to encode JSON for \(flowerID)")
127
+            return
128
+        }
129
+        
130
+        print(String(data: jsonData, encoding: .utf8)!)
131
+        
132
+        // Construct URL
133
+        var path: String
134
+        if remove {
135
+            if wishlist {
136
+                path = Constants.Services.apiRemoveFavoritePath
137
+            } else {
138
+                path = Constants.Services.apiRemoveFoundPath
139
+            }
140
+        } else {
141
+            if wishlist {
142
+                path = Constants.Services.apiPutFavoritePath
143
+            } else {
144
+                path = Constants.Services.apiPutFoundPath
145
+            }
146
+        }
147
+        
148
+        print((remove ? "removing " : "putting ") + (wishlist ? "favorite" : "found"))
149
+        let components = getBaseURLComponent(path)
150
+        
151
+        var request = URLRequest(url: components.url!)
152
+        request.httpMethod = "POST"
153
+        request.httpBody = jsonData
154
+        
155
+        // Send POST request
156
+        URLSession.shared.dataTask(with: request) { data, response, error in
157
+            print(response ?? "No response")
158
+            if let httpResponse = response as? HTTPURLResponse {
159
+                DispatchQueue.main.async {
160
+                    if httpResponse.statusCode == 200 {
161
+                        // alert that we removed favorite
162
+                        print("Success!")
163
+                    } else {
164
+                        // alert that we couldn't remove favorite
165
+                        print("Error! \(httpResponse.statusCode)")
166
+                    }
167
+                }
168
+            }
169
+        }.resume()
170
+    }
171
+    
172
+    
173
+    func removeFavorite(_ flowerID: Int) {
174
+        wishlistOrHistorySkeletonRequest(flowerID, remove: true, wishlist: true)
175
+    }
176
+    
177
+
178
+    func putFavorite(_ flowerID: Int) {
179
+        wishlistOrHistorySkeletonRequest(flowerID, remove: false, wishlist: true)
180
+    }
181
+    
182
+    
183
+    func removeFound(_ flowerID: Int) {
184
+        wishlistOrHistorySkeletonRequest(flowerID, remove: true, wishlist: false)
185
+    }
186
+
187
+    func putFound(_ flowerID: Int) {
188
+        wishlistOrHistorySkeletonRequest(flowerID, remove: false, wishlist: false)
189
+    }
190
+    
114 191
 }

+ 4
- 0
Flowerdex/Flowerdex/Supporting/Constants.swift Целия файл

@@ -20,6 +20,10 @@ struct Constants {
20 20
         static let apiGetFlowersPath = "/~victor.hernandez17/flowerdex/listFlowers.php"
21 21
         static let apiLoginPath = "/~victor.hernandez17/flowerdex/login.php"
22 22
         static let apiRegistrationPath = "/~victor.hernandez17/flowerdex/signup.php"
23
+        static let apiPutFavoritePath = "/~victor.hernandez17/flowerdex/putFavoriteFlower.php"
24
+        static let apiRemoveFavoritePath = "/~victor.hernandez17/flowerdex/removeFavoriteFlower.php"
25
+        static let apiPutFoundPath = "/~victor.hernandez17/flowerdex/putFoundFlower.php"
26
+        static let apiRemoveFoundPath = "/~victor.hernandez17/flowerdex/removeFoundFlower.php"
23 27
     }
24 28
     
25 29
     struct Colors {

+ 21
- 11
Flowerdex/Flowerdex/View/Discover Page/FlowerCard.swift Целия файл

@@ -9,7 +9,7 @@ import SwiftUI
9 9
 
10 10
 struct FlowerCard: View {
11 11
     
12
-    var flower: FlowerItem
12
+    var flower: Flower
13 13
     @ObservedObject var imageManager = ImageManager()
14 14
     var size: CGFloat = 150
15 15
     @Environment(\.colorScheme) var colorScheme
@@ -24,7 +24,7 @@ struct FlowerCard: View {
24 24
                     .aspectRatio(contentMode: .fill)
25 25
                     .frame(width: self.size, height: self.size)
26 26
                     .background(colorScheme == .dark ? Constants.Colors.darkGrayColor : Color.white)
27
-                CardDescription(commonName: self.flower.commonName, genus: self.flower.genus, family: self.flower.family, size: self.size, isFavorite: self.flower.isFavorite)
27
+                CardDescription(flower: flower, size: size, isFavoriteLocal: flower.isFavorite)
28 28
             }
29 29
             
30 30
         }
@@ -40,31 +40,41 @@ struct FlowerCard: View {
40 40
 
41 41
 struct CardDescription: View {
42 42
     
43
-    var commonName: String
44
-    var genus: String
45
-    var family: String
43
+    var flower: Flower
46 44
     var size: CGFloat
47
-    var isFavorite: Bool
45
+    @State var isFavoriteLocal: Bool
46
+    @EnvironmentObject var fModel: FlowerService
48 47
     @Environment(\.colorScheme) var colorScheme
49 48
     
50 49
     var body: some View {
51 50
         VStack(alignment: .leading) {
52
-            Text(self.commonName.capitalized)
51
+            Text(self.flower.commonName.capitalized)
53 52
                 .font(.headline)
54 53
             Spacer()
55 54
             HStack {
56
-                Text(self.genus + " > " + self.family)
55
+                Text(self.flower.genus + " > " + self.flower.family)
57 56
                     .font(.caption)
58 57
                 Spacer()
59
-                Button(action: {print("hello")}) { // 
60
-                    if self.isFavorite {
58
+                Button(action: {
59
+                    
60
+                    // Depending on past value
61
+                    if self.isFavoriteLocal {
62
+                        fModel.removeFavorite(self.flower.id)
63
+                    } else {
64
+                        fModel.putFavorite(self.flower.id)
65
+                    }
66
+                    
67
+                    // Change value after request
68
+                    self.isFavoriteLocal.toggle()
69
+                    
70
+                }) {
71
+                    if self.isFavoriteLocal {
61 72
                         Image(systemName: "star.fill")
62 73
                             .foregroundColor(.yellow)
63 74
                     } else {
64 75
                         Image(systemName: "star")
65 76
                             .foregroundColor(.black)
66 77
                     }
67
-                    
68 78
                 }
69 79
             }
70 80
         }

+ 19
- 7
Flowerdex/Flowerdex/View/Discover Page/FlowerDetailView.swift Целия файл

@@ -9,9 +9,10 @@ import SwiftUI
9 9
 
10 10
 struct FlowerDetailView: View {
11 11
     
12
-    var flower: FlowerItem
12
+    var flower: Flower
13
+    @State var hasBeenFoundLocal: Bool
13 14
     @ObservedObject var imageManager = ImageManager()
14
-//    @ObservedObject var foundManager = FoundManager()
15
+    @EnvironmentObject var fModel: FlowerService
15 16
     var size: CGFloat = 300
16 17
     
17 18
     var body: some View {
@@ -21,11 +22,22 @@ struct FlowerDetailView: View {
21 22
                     .font(.title)
22 23
                     .fontWeight(/*@START_MENU_TOKEN@*/.semibold/*@END_MENU_TOKEN@*/)
23 24
                     .foregroundColor(Constants.Colors.blueGray)
24
-                    
25 25
                 //                .frame(width: .infinity, alignment: .center)
26 26
                 Spacer()
27
-                Button(action: {print("hello")}) { //self.hasBeenFound.toggle()
28
-                    if self.flower.hasBeenFound {
27
+                Button(action: {
28
+                    
29
+                    // Depending on past value
30
+                    if self.hasBeenFoundLocal {
31
+                        fModel.removeFound(self.flower.id)
32
+                    } else {
33
+                        fModel.putFound(self.flower.id)
34
+                    }
35
+                    
36
+                    // Change value after request
37
+                    self.hasBeenFoundLocal.toggle()
38
+                    
39
+                }) {
40
+                    if self.hasBeenFoundLocal {
29 41
                         Image(systemName: "eye")
30 42
                             .font(.title)
31 43
                             .foregroundColor(Constants.Colors.rausch)
@@ -59,7 +71,7 @@ struct FlowerDetailView: View {
59 71
 
60 72
 // TODO: account for text overflow
61 73
 struct FlowerInformationPane: View {
62
-    var flower: FlowerItem
74
+    var flower: Flower
63 75
     var body: some View {
64 76
         HStack {
65 77
             VStack(alignment: .leading, spacing: nil) {
@@ -95,6 +107,6 @@ struct FlowerInformationPane: View {
95 107
 
96 108
 struct FlowerDetailView_Previews: PreviewProvider {
97 109
     static var previews: some View {
98
-        FlowerDetailView(flower: dummyFlowers[0])
110
+        FlowerDetailView(flower: dummyFlowers[0], hasBeenFoundLocal: true)
99 111
     }
100 112
 }

+ 2
- 2
Flowerdex/Flowerdex/View/Discover Page/FlowersList.swift Целия файл

@@ -8,7 +8,7 @@
8 8
 import SwiftUI
9 9
 
10 10
 struct FlowersList: View {
11
-    var flowerList: [FlowerItem]
11
+    var flowerList: [Flower]
12 12
     var body: some View {
13 13
         if flowerList.count == 0 {
14 14
             // TODO: make this centered vertically within parent ScrollView
@@ -16,7 +16,7 @@ struct FlowersList: View {
16 16
         } else {
17 17
             LazyVStack {
18 18
                 ForEach(flowerList) { flower in
19
-                    NavigationLink(destination: FlowerDetailView(flower: flower)) {
19
+                    NavigationLink(destination: FlowerDetailView(flower: flower, hasBeenFoundLocal: flower.hasBeenFound)) {
20 20
                         FlowerCard(flower: flower)
21 21
                     }
22 22
                     .foregroundColor(Constants.Colors.blueGray)