From 28ae1cc8c285e4cde75eba11a5a4b5f3c114b3af Mon Sep 17 00:00:00 2001 From: Eric Wang Date: Fri, 8 Dec 2023 10:40:00 -0500 Subject: [PATCH] Your commit message --- app/newHere1/newHere/Utils/api_call.swift | 2 + .../newHere/Views/Login/LoginView.swift | 2 +- app/newHere1/newHere/Views/Post/Post.swift | 47 ++++++++++++------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/app/newHere1/newHere/Utils/api_call.swift b/app/newHere1/newHere/Utils/api_call.swift index ef89411..2b820ef 100644 --- a/app/newHere1/newHere/Utils/api_call.swift +++ b/app/newHere1/newHere/Utils/api_call.swift @@ -355,6 +355,8 @@ func deleteFriendByName(userId: String, friendName: String, completion: @escapin func filterMessages(id: String, messages: [Message], location: (latitude: Double, longitude: Double), maxDistance: Double, friendsList: [String]) -> [Message] { return messages.filter { (message: Message) -> Bool in + print(friendsList.contains(message.user_id)) + let messageLocation = (latitude: message.location.coordinate.latitude, longitude: message.location.coordinate.longitude) let distance = haversineDistance(la1: location.latitude, lo1: location.longitude, la2: messageLocation.latitude, lo2: messageLocation.longitude) * earthRadiusKm diff --git a/app/newHere1/newHere/Views/Login/LoginView.swift b/app/newHere1/newHere/Views/Login/LoginView.swift index 77de485..50b4e2f 100644 --- a/app/newHere1/newHere/Views/Login/LoginView.swift +++ b/app/newHere1/newHere/Views/Login/LoginView.swift @@ -84,7 +84,7 @@ struct LoginView: View { // Navigation link to registration view NavigationLink(destination: RegistrationView(isRegistered: $isRegistered)) { - Text("Don't have an account? Signup") + Text("Don't have an account? Sign Up") .foregroundColor(Color.gray) } .padding() diff --git a/app/newHere1/newHere/Views/Post/Post.swift b/app/newHere1/newHere/Views/Post/Post.swift index e0e3938..63e8708 100644 --- a/app/newHere1/newHere/Views/Post/Post.swift +++ b/app/newHere1/newHere/Views/Post/Post.swift @@ -17,6 +17,7 @@ import Foundation * Note: * - It includes a close button to dismiss the view and leverages environment objects like `messageState` and `locationDataManager`. */ + struct PostsPopup: View { @Binding var isPresented: Bool // @Binding var storedMessages: [Message] @@ -24,6 +25,8 @@ struct PostsPopup: View { @State var noteMessage: String = "" @State var isEditing = false + @State private var onlyFriendsVisibility = false + var messageState: MessageState let senderName: String = "Username" @@ -72,22 +75,32 @@ struct PostsPopup: View { // HStack for horizontal alignment of share and post buttons HStack { - // Share button (placeholder action) - Button(action: { - // Share Action - }, label: { - Image(systemName: "square.and.arrow.up.fill") - .resizable() - .foregroundColor(.white) - .frame(width: 24, height: 24) - .padding(.leading, 20) - }) - Spacer() + Toggle(isOn: $onlyFriendsVisibility) { + Text("Friends") + .frame(maxWidth: .infinity, alignment: .trailing) + } + +// Button(action: { +// // Share Action +// }, label: { +// Image(systemName: "square.and.arrow.up.fill") +// .resizable() +// .foregroundColor(.white) +// .frame(width: 24, height: 24) +// .padding(.leading, 20) +// .scaledToFit() +// }) + + Spacer(minLength: 75) // Post button triggers message posting action Button(action: { - postMessage(user_id: userId, text: noteMessage, visibility: "friends", locationDataManager: locationDataManager) { + var visibilityState: String = "public" + if (onlyFriendsVisibility) { + visibilityState = "friends" + } + postMessage(user_id: userId, text: noteMessage, visibility: visibilityState, locationDataManager: locationDataManager) { result in switch result { case .success(let response): @@ -100,13 +113,11 @@ struct PostsPopup: View { user_id: userId, location: response.location.toCLLocation(), messageStr: response.text, - visibility: "Public") - // Use newMessage here - // self.storedMessages.append(newMessage) + visibility: response.visibility) // Update messageState with the new message messageState.currentMessage = newMessage - + print("posted with \(newMessage.visibility) visiblity") } catch { // Handle the error print("Error: \(error)") @@ -126,8 +137,8 @@ struct PostsPopup: View { .padding(.trailing, 20) }) } - .padding(.horizontal, 30) - .padding(.bottom, 25) +// .padding(.horizontal, 30) +// .padding(.bottom, 25) } } .frame(width: geometry.size.width - 40, height: geometry.size.width - 40)