Skip to content

Commit

Permalink
Merge pull request #25 from yale-swe/post-visibility-toggle
Browse files Browse the repository at this point in the history
Your commit message
  • Loading branch information
ericwang07 committed Dec 8, 2023
2 parents 7d83954 + 28ae1cc commit 0336e89
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
2 changes: 2 additions & 0 deletions app/newHere1/newHere/Utils/api_call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,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

Expand Down
2 changes: 1 addition & 1 deletion app/newHere1/newHere/Views/Login/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 29 additions & 18 deletions app/newHere1/newHere/Views/Post/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ 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]

@State var noteMessage: String = ""
@State var isEditing = false

@State private var onlyFriendsVisibility = false

var messageState: MessageState

let senderName: String = "Username"
Expand Down Expand Up @@ -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):
Expand All @@ -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)")
Expand All @@ -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)
Expand Down

0 comments on commit 0336e89

Please sign in to comment.