kanno927 commited on
Commit
cc22e3a
·
1 Parent(s): afdbffc

complete ui/ux and make api for sending request to server

Browse files
.DS_Store ADDED
Binary file (6.15 kB). View file
 
WatchApp/.DS_Store ADDED
Binary file (6.15 kB). View file
 
WatchApp/WatchApp Watch App/ContentView.swift CHANGED
@@ -2,10 +2,11 @@
2
  // ContentView.swift
3
  // WatchApp Watch App
4
  //
5
- // Created by DarkHorse on 6/28/23.
6
  //
7
 
8
  import SwiftUI
 
9
 
10
  struct ChatMessage: Hashable {
11
  let message: String
@@ -23,45 +24,147 @@ struct ChatBubble: Shape {
23
  }
24
  }
25
 
 
 
26
  struct ContentView: View {
27
  @State private var messages: [ChatMessage] = []
28
- @State private var newMessage = ""
 
 
 
29
 
30
  var body: some View {
31
- VStack {
32
- List {
33
- ForEach(messages, id: \.self) { message in
34
- HStack {
35
- if message.isUser {
36
- Spacer()
37
- Text(message.message)
38
- .foregroundColor(.white)
39
- .padding(10)
40
- .background(Color.blue)
41
- .clipShape(ChatBubble(isUser: message.isUser))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  } else {
43
- Text(message.message)
44
- .foregroundColor(.white)
45
- .padding(10)
46
- .background(Color.gray)
47
- .clipShape(ChatBubble(isUser: message.isUser))
48
- Spacer()
49
  }
50
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- HStack {
55
- TextField("Message...", text: $newMessage)
56
- Button(action: {
57
- let userMessage = ChatMessage(message: newMessage, isUser: true)
58
- messages.append(userMessage)
59
- newMessage = ""
60
- }) {
61
- Text("Send")
62
  }
63
  }
64
- .padding()
65
  }
66
  }
67
  }
 
2
  // ContentView.swift
3
  // WatchApp Watch App
4
  //
5
+ // Created by Hideki Sato on 6/27/23.
6
  //
7
 
8
  import SwiftUI
9
+ import KeychainSwift
10
 
11
  struct ChatMessage: Hashable {
12
  let message: String
 
24
  }
25
  }
26
 
27
+
28
+
29
  struct ContentView: View {
30
  @State private var messages: [ChatMessage] = []
31
+ @State private var newMessage = ""
32
+ @State private var uuid: String = "956a11be45cba4a4"
33
+ @State var showSettingsView = false
34
+
35
 
36
  var body: some View {
37
+ if !showSettingsView {
38
+
39
+ VStack {
40
+ Button(action: {
41
+ // Handle settings button tap
42
+ self.showSettingsView.toggle() // example of usage
43
+
44
+ }) {
45
+ Image(systemName: "gearshape.fill") // "gearshape.fill" is a system symbol for settings
46
+ .resizable()
47
+ .frame(width: 15, height: 15) // Set the size of the button
48
+ }
49
+ .frame(width: 50, height: 30)
50
+ .background(Color.clear)
51
+
52
+ List {
53
+ ForEach(messages, id: \.self) { message in
54
+ HStack {
55
+ if message.isUser {
56
+ Spacer()
57
+ Text(message.message)
58
+ .foregroundColor(.white)
59
+ .padding(5)
60
+ .background(Color.blue)
61
+ .clipShape(ChatBubble(isUser: message.isUser))
62
+ } else {
63
+ Text(message.message)
64
+ .foregroundColor(.black)
65
+ .padding(5)
66
+ .background(Color.gray)
67
+ .clipShape(ChatBubble(isUser: message.isUser))
68
+ Spacer()
69
+ }
70
+ }.listRowBackground(Color.clear)
71
+ }
72
+ }.listStyle(PlainListStyle())
73
+
74
+
75
+ HStack() {
76
+ TextField("Message...", text: $newMessage).frame(width: 120.0, height: 0)
77
+ Button(action: {
78
+ let keychain = KeychainSwift()
79
+
80
+ // Try to get the UUID from the keychain
81
+ if let uuid = keychain.get("uuid") {
82
  } else {
83
+ let uuid = "956a11be45cba4a4"
84
+ keychain.set(uuid, forKey: "uuid")
 
 
 
 
85
  }
86
+
87
+ let userMessage = ChatMessage(message: newMessage, isUser: true)
88
+ messages.append(userMessage)
89
+
90
+ // Replace this URL with your server's URL
91
+ if let url = URL(string: "https://ttt246-brain.hf.space/sendNotification") {
92
+ var request = URLRequest(url: url)
93
+ request.httpMethod = "POST" // Change this to any HTTP method you want
94
+ request.addValue("application/json", forHTTPHeaderField: "Content-Type") // Add any necessary headers
95
+
96
+ let confsData: [String: Any] = [
97
+ "openai_key": "",
98
+ "pinecone_key": "",
99
+ "pinecone_env": "",
100
+ "firebase_key": "",
101
+ "token":"cI3EvimJQv-G5imdWrBprf:APA91bEZ5u6uq9Yq4a6NglN0L9pVM7p-rlxKB_FikbfKlzHnZT5GeAjxF0deuPT2GurS8bK6JTE2XPZLQqbsrtjxeRGhGOH5INoQ7MrRlr4TR3xFswKxJSkfi1aBUWDaLGALeirZ7GuZ",
102
+ "uuid": uuid,
103
+ "settings": [
104
+ "temperature": 0.6
105
+ ]
106
+ ]
107
+
108
+ let postData: [String: Any] = ["confs": confsData, "message": newMessage]
109
+
110
+ do {
111
+ let jsonData = try JSONSerialization.data(withJSONObject: postData, options: .prettyPrinted)
112
+ URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in
113
+ guard error == nil, let data = data else {
114
+ print("Error: \(error?.localizedDescription ?? "Unknown error")")
115
+ return
116
+ }
117
+
118
+ do {
119
+ // Here we are converting data into JSON using JSONSerialization
120
+ if let jsonResult = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
121
+ if let result = jsonResult["result"] as? [String: Any], let content = result["content"] as? String {
122
+ DispatchQueue.main.async {
123
+ let serverResponse = ChatMessage(message: content, isUser: false)
124
+ messages.append(serverResponse)
125
+ }
126
+ }
127
+ }
128
+ } catch {
129
+ print("JSONSerialization error: \(error.localizedDescription)")
130
+ }
131
+
132
+ }.resume()
133
+ } catch {
134
+ print("Error: \(error.localizedDescription)")
135
+ }
136
+ }
137
+ newMessage = ""
138
+ }) {
139
+ Image(systemName: "paperplane.fill")
140
+ }.frame(width: 50.0, height: 35)
141
  }
142
+ }.padding().edgesIgnoringSafeArea(.all)
143
+ } else {
144
+ VStack {
145
+ TextField("uuid", text: $uuid)
146
+ .padding()
147
+ HStack {
148
+ Button(action: {
149
+ let keychain = KeychainSwift()
150
+ keychain.set("\($uuid)", forKey: "uuid")
151
+
152
+ self.showSettingsView.toggle()
153
+ }) {
154
+ Text("OK")
155
+ }
156
+ .frame(width: 70, height: 30)
157
+ .background(Color.clear)
158
 
159
+ Button(action: {
160
+ self.showSettingsView.toggle()
161
+ }) {
162
+ Text("Cancel")
163
+ }
164
+ .frame(width: 70, height: 30)
165
+ .background(Color.clear)
 
166
  }
167
  }
 
168
  }
169
  }
170
  }
WatchApp/WatchApp.xcodeproj/project.pbxproj CHANGED
@@ -9,12 +9,13 @@
9
  /* Begin PBXBuildFile section */
10
  FE56FAE22A4C5810008410B4 /* WatchApp Watch App.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = FE56FAE12A4C5810008410B4 /* WatchApp Watch App.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
11
  FE56FAE72A4C5810008410B4 /* WatchAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FAE62A4C5810008410B4 /* WatchAppApp.swift */; };
12
- FE56FAE92A4C5810008410B4 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FAE82A4C5810008410B4 /* ContentView.swift */; };
13
  FE56FAEB2A4C5814008410B4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FE56FAEA2A4C5814008410B4 /* Assets.xcassets */; };
14
  FE56FAEE2A4C5814008410B4 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FE56FAED2A4C5814008410B4 /* Preview Assets.xcassets */; };
15
  FE56FAF82A4C5814008410B4 /* WatchApp_Watch_AppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FAF72A4C5814008410B4 /* WatchApp_Watch_AppTests.swift */; };
16
  FE56FB022A4C5814008410B4 /* WatchApp_Watch_AppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FB012A4C5814008410B4 /* WatchApp_Watch_AppUITests.swift */; };
17
  FE56FB042A4C5814008410B4 /* WatchApp_Watch_AppUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FB032A4C5814008410B4 /* WatchApp_Watch_AppUITestsLaunchTests.swift */; };
 
 
18
  /* End PBXBuildFile section */
19
 
20
  /* Begin PBXContainerItemProxy section */
@@ -74,6 +75,7 @@
74
  isa = PBXFrameworksBuildPhase;
75
  buildActionMask = 2147483647;
76
  files = (
 
77
  );
78
  runOnlyForDeploymentPostprocessing = 0;
79
  };
@@ -184,6 +186,9 @@
184
  dependencies = (
185
  );
186
  name = "WatchApp Watch App";
 
 
 
187
  productName = "WatchApp Watch App";
188
  productReference = FE56FAE12A4C5810008410B4 /* WatchApp Watch App.app */;
189
  productType = "com.apple.product-type.application";
@@ -259,6 +264,9 @@
259
  Base,
260
  );
261
  mainGroup = FE56FAD42A4C580F008410B4;
 
 
 
262
  productRefGroup = FE56FADC2A4C5810008410B4 /* Products */;
263
  projectDirPath = "";
264
  projectRoot = "";
@@ -309,7 +317,7 @@
309
  isa = PBXSourcesBuildPhase;
310
  buildActionMask = 2147483647;
311
  files = (
312
- FE56FAE92A4C5810008410B4 /* ContentView.swift in Sources */,
313
  FE56FAE72A4C5810008410B4 /* WatchAppApp.swift in Sources */,
314
  );
315
  runOnlyForDeploymentPostprocessing = 0;
@@ -680,6 +688,25 @@
680
  defaultConfigurationName = Release;
681
  };
682
  /* End XCConfigurationList section */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
683
  };
684
  rootObject = FE56FAD52A4C580F008410B4 /* Project object */;
685
  }
 
9
  /* Begin PBXBuildFile section */
10
  FE56FAE22A4C5810008410B4 /* WatchApp Watch App.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = FE56FAE12A4C5810008410B4 /* WatchApp Watch App.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
11
  FE56FAE72A4C5810008410B4 /* WatchAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FAE62A4C5810008410B4 /* WatchAppApp.swift */; };
 
12
  FE56FAEB2A4C5814008410B4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FE56FAEA2A4C5814008410B4 /* Assets.xcassets */; };
13
  FE56FAEE2A4C5814008410B4 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FE56FAED2A4C5814008410B4 /* Preview Assets.xcassets */; };
14
  FE56FAF82A4C5814008410B4 /* WatchApp_Watch_AppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FAF72A4C5814008410B4 /* WatchApp_Watch_AppTests.swift */; };
15
  FE56FB022A4C5814008410B4 /* WatchApp_Watch_AppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FB012A4C5814008410B4 /* WatchApp_Watch_AppUITests.swift */; };
16
  FE56FB042A4C5814008410B4 /* WatchApp_Watch_AppUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FB032A4C5814008410B4 /* WatchApp_Watch_AppUITestsLaunchTests.swift */; };
17
+ FE56FB142A4C80A5008410B4 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE56FAE82A4C5810008410B4 /* ContentView.swift */; };
18
+ FE673FCB2A4CDBF7003EF230 /* KeychainSwift in Frameworks */ = {isa = PBXBuildFile; productRef = FE673FCA2A4CDBF7003EF230 /* KeychainSwift */; };
19
  /* End PBXBuildFile section */
20
 
21
  /* Begin PBXContainerItemProxy section */
 
75
  isa = PBXFrameworksBuildPhase;
76
  buildActionMask = 2147483647;
77
  files = (
78
+ FE673FCB2A4CDBF7003EF230 /* KeychainSwift in Frameworks */,
79
  );
80
  runOnlyForDeploymentPostprocessing = 0;
81
  };
 
186
  dependencies = (
187
  );
188
  name = "WatchApp Watch App";
189
+ packageProductDependencies = (
190
+ FE673FCA2A4CDBF7003EF230 /* KeychainSwift */,
191
+ );
192
  productName = "WatchApp Watch App";
193
  productReference = FE56FAE12A4C5810008410B4 /* WatchApp Watch App.app */;
194
  productType = "com.apple.product-type.application";
 
264
  Base,
265
  );
266
  mainGroup = FE56FAD42A4C580F008410B4;
267
+ packageReferences = (
268
+ FE673FC92A4CDBF7003EF230 /* XCRemoteSwiftPackageReference "keychain-swift" */,
269
+ );
270
  productRefGroup = FE56FADC2A4C5810008410B4 /* Products */;
271
  projectDirPath = "";
272
  projectRoot = "";
 
317
  isa = PBXSourcesBuildPhase;
318
  buildActionMask = 2147483647;
319
  files = (
320
+ FE56FB142A4C80A5008410B4 /* ContentView.swift in Sources */,
321
  FE56FAE72A4C5810008410B4 /* WatchAppApp.swift in Sources */,
322
  );
323
  runOnlyForDeploymentPostprocessing = 0;
 
688
  defaultConfigurationName = Release;
689
  };
690
  /* End XCConfigurationList section */
691
+
692
+ /* Begin XCRemoteSwiftPackageReference section */
693
+ FE673FC92A4CDBF7003EF230 /* XCRemoteSwiftPackageReference "keychain-swift" */ = {
694
+ isa = XCRemoteSwiftPackageReference;
695
+ repositoryURL = "https://github.com/evgenyneu/keychain-swift.git";
696
+ requirement = {
697
+ kind = upToNextMajorVersion;
698
+ minimumVersion = 20.0.0;
699
+ };
700
+ };
701
+ /* End XCRemoteSwiftPackageReference section */
702
+
703
+ /* Begin XCSwiftPackageProductDependency section */
704
+ FE673FCA2A4CDBF7003EF230 /* KeychainSwift */ = {
705
+ isa = XCSwiftPackageProductDependency;
706
+ package = FE673FC92A4CDBF7003EF230 /* XCRemoteSwiftPackageReference "keychain-swift" */;
707
+ productName = KeychainSwift;
708
+ };
709
+ /* End XCSwiftPackageProductDependency section */
710
  };
711
  rootObject = FE56FAD52A4C580F008410B4 /* Project object */;
712
  }
WatchApp/WatchApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "pins" : [
3
+ {
4
+ "identity" : "keychain-swift",
5
+ "kind" : "remoteSourceControl",
6
+ "location" : "https://github.com/evgenyneu/keychain-swift.git",
7
+ "state" : {
8
+ "revision" : "d108a1fa6189e661f91560548ef48651ed8d93b9",
9
+ "version" : "20.0.0"
10
+ }
11
+ }
12
+ ],
13
+ "version" : 2
14
+ }
WatchApp/WatchApp.xcodeproj/project.xcworkspace/xcuserdata/darkhorse.xcuserdatad/UserInterfaceState.xcuserstate CHANGED
Binary files a/WatchApp/WatchApp.xcodeproj/project.xcworkspace/xcuserdata/darkhorse.xcuserdatad/UserInterfaceState.xcuserstate and b/WatchApp/WatchApp.xcodeproj/project.xcworkspace/xcuserdata/darkhorse.xcuserdatad/UserInterfaceState.xcuserstate differ