Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ewang001 committed Nov 27, 2023
2 parents beb4350 + ae9dcb0 commit 08148a1
Show file tree
Hide file tree
Showing 30 changed files with 842 additions and 416 deletions.
Binary file modified .DS_Store
Binary file not shown.
104 changes: 0 additions & 104 deletions Message_View.swift

This file was deleted.

Binary file modified app/.DS_Store
Binary file not shown.
Binary file modified app/newHere1/.DS_Store
Binary file not shown.
28 changes: 25 additions & 3 deletions app/newHere1/newHere/Friends.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// Description: SwiftUI View for managing the user's friends.

//This view presents a pop-up interface for users to search, add, and delete friends. It includes a top bar with a close button, a search bar with an add friend button, and a list displaying the user's friends with delete functionality.
//
//Properties:
//- isPresented: Binding to control the visibility of the pop-up.
//- userId: Binding to represent the current user's ID.
//- friendsList: State variable to hold the list of user's friends.
//- errorMessage: State variable to handle and display errors.
//- searchText: State variable for input in the search bar.
//
//Functionality:
//- Users can search for friends using the search bar.
//- The "Add Friend" button triggers the addition of a friend.
//- Friend entries include a delete button for removing friends.
//- Errors, if any, are displayed at the top of the view.

import SwiftUI

struct Friends: View {
Expand All @@ -11,7 +28,7 @@ struct Friends: View {
var body: some View {
VStack {

// top bar
// top bar with close button
HStack {
Spacer()
Button(action: {
Expand All @@ -27,7 +44,7 @@ struct Friends: View {
.padding(.trailing, 20) // Adjust the position of the close button
}

// search bar
// search bar and add friend button
HStack {
TextField("Search...", text: $searchText)
.padding(7)
Expand Down Expand Up @@ -56,6 +73,7 @@ struct Friends: View {
.keyboardType(.webSearch)

Button(action: {
// Add friend when the "Add Friend" button is tapped
addFriendByName(userId: userId, friendName: searchText) {
result in
switch result {
Expand All @@ -78,10 +96,13 @@ struct Friends: View {
}
.padding()

// Add friend when the "Add Friend" button is tapped
if let errorMessage = errorMessage {
Text(errorMessage)
} else {
// Friends List
List(friendsList, id: \.self) { friend in
// Each friend in the list with delete button
HStack {
Text(friend)
Spacer()
Expand All @@ -96,7 +117,7 @@ struct Friends: View {
// self.errorMessage = error.localizedDescription
// }
// }
//
// // Delete friend when the minus button is tapped
deleteFriendByName(userId: userId, friendName:friend) {
result in
switch result {
Expand All @@ -115,6 +136,7 @@ struct Friends: View {
}
}
.onAppear {
// Fetch Friends List on Appear
getAllUserFriends(userId: userId) { result in
switch result {
case .success(let response):
Expand Down
36 changes: 35 additions & 1 deletion app/newHere1/newHere/LocationDataManager.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Description: LocationDataManager Class: Manages location-related data and updates using Core Location. Converts location data to/from GeoJSON format.

//GeoJSONPoint Struct: Represents a GeoJSON Point with latitude and longitude coordinates. Provides conversion to CLLocation.
//
//CLLocation Extension: Adds a method to convert CLLocation to GeoJSONPoint.

import CoreLocation
import Combine

Expand All @@ -6,15 +12,29 @@ enum GeoJSONError: Error {
case invalidCoordinates
}

// This Codable struct represents a GeoJSON Point with latitude and longitude coordinates.

//Properties:
//- type: String representing the GeoJSON type (e.g., "Point").
//- coordinates: Array of Doubles representing latitude and longitude.
//
//Initializer:
//- Initializes a GeoJSONPoint with latitude and longitude, setting the type to "Point".
//
//Functions:
//- toCLLocation(): Converts GeoJSONPoint to CLLocation.

struct GeoJSONPoint: Codable {
let type: String
let coordinates: [Double]

// Initialize GeoJSONPoint with latitude and longitude
init (latitude: Double, longitude: Double) {
self.type = "Point"
self.coordinates = [longitude, latitude]
}

// Convert GeoJSONPoint to CLLocation
func toCLLocation() throws -> CLLocation {
guard type == "Point" else {
throw GeoJSONError.invalidType
Expand All @@ -27,16 +47,29 @@ struct GeoJSONPoint: Codable {
}

extension CLLocation {
// Convert CLLocation to GeoJSONPoint
func toGeoJSONPoint() -> GeoJSONPoint {
return GeoJSONPoint(latitude: self.coordinate.latitude, longitude: self.coordinate.longitude)
}
}

// This class manages location-related data and interactions, including handling Core Location updates and converting location data to/from GeoJSON format.

//Properties:
//- location: Published property representing the current CLLocation.
//- locationManager: CLLocationManager instance for managing location updates.
//
//Initializer:
//- Initializes a new LocationDataManager object, setting up the CLLocationManager and starting location updates.
//
//Functions:
//- locationManager(_:didUpdateLocations:): Delegate method called when location updates occur, updating the location property.

class LocationDataManager: NSObject, ObservableObject, CLLocationManagerDelegate {
@Published var location: CLLocation?
private var locationManager = CLLocationManager()


// Initialize LocationDataManager and set up CLLocationManager
override init() {
super.init()
locationManager.delegate = self
Expand All @@ -45,6 +78,7 @@ class LocationDataManager: NSObject, ObservableObject, CLLocationManagerDelegate
locationManager.startUpdatingLocation()
}

// CLLocationManagerDelegate method called on location updates
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let newLocation = locations.last {
self.location = newLocation
Expand Down
14 changes: 14 additions & 0 deletions app/newHere1/newHere/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
// Created by Eric Wang on 10/28/23.
//

// Description: This class represents a message object, including its unique identifier, associated user ID, geographic location, and message content.

//Properties:
//- id: A unique identifier for the message.
//- user_id: The user ID of the sender associated with the message.
//- location: A CLLocation object representing the geographic location associated with the message.
//- messageStr: The string content of the message.
//
//Initializer:
//- Initializes a new Message object with the provided parameters.
//
//Note: This class is utilized for managing messages within the application and may be used in conjunction with location-based features.

import Foundation
import CoreLocation

Expand All @@ -15,6 +28,7 @@ class Message {
var location: CLLocation
var messageStr: String

// Initialize Message object with provided parameters
init(id:String, user_id: String, location:CLLocation, messageStr: String) {
self.id = id
self.user_id = user_id
Expand Down
27 changes: 26 additions & 1 deletion app/newHere1/newHere/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
// Created by Liyang Wang on 10/10/23.
//

// Description: SwiftUI View for displaying and posting messages.

//This view includes a pop-up interface for composing and sharing messages. Users can input text, share content, and post messages to the server. The interface is designed with SwiftUI elements, allowing dynamic adjustments based on screen geometry.
//
//Properties:
//- isPresented: Binding to control the visibility of the pop-up.
//- noteMessage: State variable to hold the message text.
//- messageState: EnvironmentObject for managing message-related state.
//- senderName: Constant string representing the username.
//- locationDataManager: EnvironmentObject for handling location data.
//
//Functionality:
//- Users can compose messages using a TextEditor.
//- Share and post buttons trigger respective actions.
//- Messages are posted to the server with associated user and location data.

import SwiftUI
import CoreLocation
import Foundation
Expand All @@ -25,12 +41,15 @@ struct PostsPopup: View {


var body: some View {
// GeometryReader for dynamic layout based on screen size
GeometryReader { geometry in
// ZStack for layering views
ZStack {

// VStack for vertical arrangement of UI elements
VStack(spacing: 10) {
Spacer()

// HStack for horizontal alignment of close button
HStack {
Spacer()
Button(action: {
Expand All @@ -47,18 +66,22 @@ struct PostsPopup: View {
}
.padding(.leading, 20)

// ZStack for styling the message input area
ZStack {
RoundedRectangle(cornerRadius: 10)
.fill(Color.white)
.shadow(radius: 5)

// VStack for arranging TextEditor and buttons vertically
VStack {
TextEditor(text: $noteMessage)
.padding(.all, 30)

Spacer(minLength: 20)

// HStack for horizontal alignment of share and post buttons
HStack {
// Share button (placeholder action)
Button(action: {
// Share Action
}, label: {
Expand All @@ -71,6 +94,7 @@ struct PostsPopup: View {

Spacer()

// Post button triggers message posting action
Button(action: {
postMessage(user_id: userId, text: noteMessage, visibility: "friends", locationDataManager: locationDataManager) {
result in
Expand All @@ -88,6 +112,7 @@ struct PostsPopup: View {
// Use newMessage here
// self.storedMessages.append(newMessage)

// Update messageState with the new message
messageState.currentMessage = newMessage

} catch {
Expand Down
Loading

0 comments on commit 08148a1

Please sign in to comment.