Pārlūkot izejas kodu

Added logout screen (must find way of notifying MainView of change)

Víctor Hernández 4 gadus atpakaļ
vecāks
revīzija
d940d6f25c

+ 13
- 1
Flowerdex/Flowerdex.xcodeproj/project.pbxproj Parādīt failu

@@ -17,6 +17,7 @@
17 17
 		A5799DB4259157AC003E975D /* FlowerVerbose.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5799DB3259157AC003E975D /* FlowerVerbose.swift */; };
18 18
 		A5799DB72591594D003E975D /* HistoryResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5799DB62591594D003E975D /* HistoryResponseModel.swift */; };
19 19
 		A5799DBB25915C2B003E975D /* FlowerVerboseDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5799DBA25915C2B003E975D /* FlowerVerboseDetailView.swift */; };
20
+		A5799DC2259162E2003E975D /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5799DC1259162E2003E975D /* SettingsView.swift */; };
20 21
 		A58640BA258F30AD00F626AB /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A58640B9258F30AD00F626AB /* LoginView.swift */; };
21 22
 		A58640BE258F30F200F626AB /* RegisterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A58640BD258F30F200F626AB /* RegisterView.swift */; };
22 23
 		A59A2741254556880052319F /* FlowerdexApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59A2740254556880052319F /* FlowerdexApp.swift */; };
@@ -52,6 +53,7 @@
52 53
 		A5799DB3259157AC003E975D /* FlowerVerbose.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerVerbose.swift; sourceTree = "<group>"; };
53 54
 		A5799DB62591594D003E975D /* HistoryResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryResponseModel.swift; sourceTree = "<group>"; };
54 55
 		A5799DBA25915C2B003E975D /* FlowerVerboseDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowerVerboseDetailView.swift; sourceTree = "<group>"; };
56
+		A5799DC1259162E2003E975D /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
55 57
 		A58640B9258F30AD00F626AB /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
56 58
 		A58640BD258F30F200F626AB /* RegisterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterView.swift; sourceTree = "<group>"; };
57 59
 		A59A273D254556880052319F /* Flowerdex.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Flowerdex.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -119,12 +121,21 @@
119 121
 				A58640AE258F213600F626AB /* Authentication Page */,
120 122
 				A5EE38B6257819AA0014D0BE /* Discover Page */,
121 123
 				A5EA2F382590A61000699182 /* History Page */,
122
-				A5EA2F3E2590A65A00699182 /* MainView.swift */,
124
+				A5799DC0259162C2003E975D /* Settings Page */,
123 125
 				A5EE38B2257818BE0014D0BE /* StatusIcons.swift */,
126
+				A5EA2F3E2590A65A00699182 /* MainView.swift */,
124 127
 			);
125 128
 			path = View;
126 129
 			sourceTree = "<group>";
127 130
 		};
131
+		A5799DC0259162C2003E975D /* Settings Page */ = {
132
+			isa = PBXGroup;
133
+			children = (
134
+				A5799DC1259162E2003E975D /* SettingsView.swift */,
135
+			);
136
+			path = "Settings Page";
137
+			sourceTree = "<group>";
138
+		};
128 139
 		A58640AE258F213600F626AB /* Authentication Page */ = {
129 140
 			isa = PBXGroup;
130 141
 			children = (
@@ -306,6 +317,7 @@
306 317
 				A5799DBB25915C2B003E975D /* FlowerVerboseDetailView.swift in Sources */,
307 318
 				A58640BE258F30F200F626AB /* RegisterView.swift in Sources */,
308 319
 				A5EE388D2576362B0014D0BE /* FilterFields.swift in Sources */,
320
+				A5799DC2259162E2003E975D /* SettingsView.swift in Sources */,
309 321
 				A5F3271A25460C0B003BCE0F /* FlowerDetailView.swift in Sources */,
310 322
 				A58640BA258F30AD00F626AB /* LoginView.swift in Sources */,
311 323
 				A5AF3F5C2545FDEB0035AC9A /* FlowerCard.swift in Sources */,

Binārs
Flowerdex/Flowerdex.xcodeproj/project.xcworkspace/xcuserdata/victor.hernandez.xcuserdatad/UserInterfaceState.xcuserstate Parādīt failu


+ 4
- 0
Flowerdex/Flowerdex/Model/User.swift Parādīt failu

@@ -57,4 +57,8 @@ class User: Codable, Identifiable { // not a hashable struct anymore :(
57 57
         }
58 58
     }
59 59
     
60
+    static func logout() {
61
+        UserDefaults.standard.removeObject(forKey: Constants.UserDefaults.currentUser)
62
+    }
63
+    
60 64
 }

+ 6
- 0
Flowerdex/Flowerdex/View/MainView.swift Parādīt failu

@@ -21,6 +21,12 @@ struct MainView: View {
21 21
                     Image(systemName: "square.and.pencil")
22 22
                     Text("History")
23 23
                 }
24
+            
25
+            SettingsView()
26
+                .tabItem {
27
+                    Image(systemName: "gearshape")
28
+                    Text("Settings")
29
+                }
24 30
         }
25 31
         .accentColor(Constants.Colors.rausch)
26 32
     }

+ 82
- 0
Flowerdex/Flowerdex/View/Settings Page/SettingsView.swift Parādīt failu

@@ -0,0 +1,82 @@
1
+//
2
+//  SettingsView.swift
3
+//  Flowerdex
4
+//
5
+//  Created by Víctor A. Hernández on 12/21/20.
6
+//
7
+
8
+import SwiftUI
9
+
10
+struct SettingsView: View {
11
+    @State var loading = false
12
+    var body: some View {
13
+        VStack {
14
+            AccountDetails()
15
+            Spacer()
16
+    
17
+            if loading {
18
+                ProgressView("Logging out...")
19
+                Spacer()
20
+            }
21
+            
22
+            Button(action: {
23
+                User.logout()
24
+                // TODO: notify MainView of change
25
+                loading.toggle()
26
+            }) {
27
+                LogoutButtonText(loading: $loading)
28
+            }
29
+            .disabled(loading)
30
+            
31
+        }
32
+        .padding(30)
33
+    }
34
+}
35
+
36
+struct LogoutButtonText: View {
37
+    @Binding var loading: Bool
38
+    var body: some View {
39
+        Text("Logout")
40
+            .font(.headline)
41
+            .foregroundColor(.white)
42
+            .padding()
43
+            .frame(width: 220, height: 50)
44
+            .background(loading ? Color.gray : Color.red)
45
+            .cornerRadius(5)
46
+    }
47
+}
48
+
49
+struct AccountDetails: View {
50
+    var body: some View {
51
+        Text("Account Details")
52
+            .font(.largeTitle)
53
+            .fontWeight(.semibold)
54
+            .foregroundColor(Constants.Colors.blueGray)
55
+            .frame(width: 350, height: 25, alignment: .topLeading)
56
+            .padding(.bottom, 25)
57
+        VStack(alignment: .leading) {
58
+            Text("Username")
59
+                .font(.title2)
60
+                .fontWeight(.bold)
61
+                .foregroundColor(Constants.Colors.rausch)
62
+            Text(User.current.username!)
63
+                .font(.title3)
64
+                .foregroundColor(Constants.Colors.blueGray)
65
+                .padding(.vertical)
66
+                .padding(.leading)
67
+            Text("Email")
68
+                .font(.title2)
69
+                .fontWeight(.bold)
70
+                .foregroundColor(Constants.Colors.rausch)
71
+            Text(User.current.email)
72
+                .font(.title3)
73
+                .foregroundColor(Constants.Colors.blueGray)
74
+                .padding(.vertical)
75
+                .padding(.leading)
76
+        }
77
+        .padding()
78
+        .frame(width: 350, alignment: .leading)
79
+        
80
+        
81
+    }
82
+}