-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/yale-swe/f23-here
- Loading branch information
Showing
15 changed files
with
461 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import SwiftUI | ||
|
||
struct Friends: View { | ||
@Binding var isPresented: Bool | ||
@Binding var userId: String | ||
|
||
// State to hold the friends list | ||
@State private var friendsList: [String] = [] | ||
@State private var errorMessage: String? | ||
@State private var searchText: String = "" | ||
|
||
var body: some View { | ||
VStack { | ||
|
||
// top bar | ||
HStack { | ||
Spacer() | ||
Button(action: { | ||
isPresented.toggle() // Close the popup | ||
}) { | ||
Text("Close") | ||
.font(.headline) | ||
.padding() | ||
.background(Color.blue) | ||
.foregroundColor(.white) | ||
.cornerRadius(10) | ||
} | ||
.padding(.trailing, 20) // Adjust the position of the close button | ||
} | ||
|
||
// search bar | ||
HStack { | ||
TextField("Search...", text: $searchText) | ||
.padding(7) | ||
.padding(.horizontal, 25) | ||
.background(Color(.systemGray6)) | ||
.cornerRadius(8) | ||
.overlay( | ||
HStack { | ||
Image(systemName: "magnifyingglass") | ||
.foregroundColor(.gray) | ||
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) | ||
.padding(.leading, 8) | ||
|
||
if !searchText.isEmpty { | ||
Button(action: { | ||
searchText = "" | ||
}) { | ||
Image(systemName: "multiply.circle.fill") | ||
.foregroundColor(.gray) | ||
.padding(.trailing, 8) | ||
} | ||
} | ||
} | ||
) | ||
.autocapitalization(.none) | ||
.keyboardType(.webSearch) | ||
|
||
Button(action: { | ||
addFriendByName(userId: userId, friendName: searchText) { | ||
result in | ||
switch result { | ||
case .success(let response): | ||
print("Friend added successfully: \(response)") | ||
case .failure(let error): | ||
print("Error adding friend: \(error.localizedDescription)") | ||
self.errorMessage = error.localizedDescription | ||
} | ||
} | ||
|
||
}) { | ||
Text("Add Friend") | ||
.padding(.horizontal, 16) | ||
.padding(.vertical, 8) | ||
.background(Color.blue) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
} | ||
.padding() | ||
|
||
if let errorMessage = errorMessage { | ||
Text(errorMessage) | ||
} else { | ||
List(friendsList, id: \.self) { friend in | ||
Text(friend) | ||
} | ||
} | ||
} | ||
.onAppear { | ||
getAllUserFriends(userId: userId) { result in | ||
switch result { | ||
case .success(let response): | ||
print("Friends fetched successfully: \(response)") | ||
// self.friendsList = response // Assuming response is [String] | ||
|
||
case .failure(let error): | ||
print("Error getting messages: \(error.localizedDescription)") | ||
self.errorMessage = error.localizedDescription | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Make sure `getAllUserFriends` has a signature similar to this: | ||
// func getAllUserFriends(userId: String, completion: @escaping (Result<[String], Error>) -> Void) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.