Skip to content

Commit

Permalink
Merge pull request #22 from yale-swe/refresh-button
Browse files Browse the repository at this point in the history
done
  • Loading branch information
ericwang07 committed Dec 8, 2023
2 parents a93a5e4 + 2e82624 commit 93e2e1e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
10 changes: 5 additions & 5 deletions app/newHere1/newHere.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
1531A8DC2AED95FD009F644E /* newHere */ = {
isa = PBXGroup;
children = (
1531A9142AEDCADB009F644E /* Message.swift */,
71D79DAD2B1578F5009A054C /* Models */,
71D79DAB2B1576DA009A054C /* Utils */,
71D79DA82B15767C009A054C /* Views */,
Expand Down Expand Up @@ -292,7 +293,6 @@
71D79DAD2B1578F5009A054C /* Models */ = {
isa = PBXGroup;
children = (
1531A9142AEDCADB009F644E /* Message.swift */,
1531A9122AEDAE2A009F644E /* LocationDataManager.swift */,
);
path = Models;
Expand Down Expand Up @@ -668,7 +668,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"newHere/Preview Content\"";
DEVELOPMENT_TEAM = W23Y365YR7;
DEVELOPMENT_TEAM = A7X36A78B2;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -691,7 +691,7 @@
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
"OTHER_SWIFT_FLAGS[arch=*]" = "-v";
PRODUCT_BUNDLE_IDENTIFIER = com.ericw.newHere;
PRODUCT_BUNDLE_IDENTIFIER = com.ericwang.newHere;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
Expand All @@ -713,7 +713,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"newHere/Preview Content\"";
DEVELOPMENT_TEAM = W23Y365YR7;
DEVELOPMENT_TEAM = A7X36A78B2;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -736,7 +736,7 @@
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
"OTHER_SWIFT_FLAGS[arch=*]" = "";
PRODUCT_BUNDLE_IDENTIFIER = com.eric.newHere;
PRODUCT_BUNDLE_IDENTIFIER = com.ericwang.newHere;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
Expand Down
File renamed without changes.
44 changes: 44 additions & 0 deletions app/newHere1/newHere/Views/ARView/CustomARViewRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ import ARKit
* - renderBubbleNodeHistory(to:messages:): Renders a history of messages as bubble nodes in random positions.
* - newBubbleNode(to:message:position:): Creates a new bubble node with a message at a specified position.
*/

class UpdateARState: ObservableObject {
@Published var updateTrue: Bool?
}


struct CustomARViewRepresentable: UIViewRepresentable {
// Environment objects for message and fetched messages states
@EnvironmentObject var messageState: MessageState
@EnvironmentObject var fetchedMessagesState: FetchedMessagesState
@EnvironmentObject var locationDataManager: LocationDataManager
@EnvironmentObject var updateARState: UpdateARState

/// Create the ARSCNView and configure it
func makeUIView(context: Context) -> ARSCNView {
Expand All @@ -31,6 +38,8 @@ struct CustomARViewRepresentable: UIViewRepresentable {
sceneView.session.run(configuration)
print("user id: \(userId)")

sceneView.scene.rootNode.childNodes.forEach { $0.removeFromParentNode() }

var friendIdList: [String] = []
// Fetch and render user's messages
getAllUserFriends(userId: userId) { result in
Expand Down Expand Up @@ -72,6 +81,41 @@ struct CustomARViewRepresentable: UIViewRepresentable {
messageState.currentMessage = nil
}

if updateARState.updateTrue == true {
uiView.scene.rootNode.childNodes.forEach { $0.removeFromParentNode() }

var friendIdList: [String] = []
// Fetch and render user's messages
getAllUserFriends(userId: userId) { result in
switch result {
case .success(let response):
print("Friends fetched successfully: \(response)")
friendIdList = response.keys.map { $0 }

case .failure(let error):
print("Error getting friends: \(error.localizedDescription)")
}
}

if let currentLocation = locationDataManager.location {
getFilteredMessages(userId: userId, location: currentLocation, friendList: friendIdList) {
result in
switch result {
case .success(let response):
print("Messages filtered successfully: \(response)")
var convertedMessages:[Message] = response
fetchedMessagesState.fetchedMessages = convertedMessages
print("fetched messages: \(fetchedMessagesState.fetchedMessages)")
renderBubbleNodeHistory(to: uiView, messages: convertedMessages)

case .failure(let error):
print("Error getting messages: \(error.localizedDescription)")
}
}
}
updateARState.updateTrue = false
}

}

/// Create a coordinator for handling ARSCNViewDelegate methods
Expand Down
9 changes: 6 additions & 3 deletions app/newHere1/newHere/Views/Home/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ struct HomePageView: View {
@State private var screenshot: UIImage?
@State private var showCaptureAlert = false

@StateObject var updateARState = UpdateARState()

@EnvironmentObject var locationDataManager: LocationDataManager



/// The body of the view, presenting the AR view along with overlay controls for navigation and interaction.
var body: some View {
ZStack{
Expand All @@ -52,15 +56,14 @@ struct HomePageView: View {
.environmentObject(messageState)
.environmentObject(fetchedMessagesState)
.environmentObject(locationDataManager)
.environmentObject(updateARState)
.overlay(alignment: .bottom){
// Overlay containing buttons for various features like map, messages, posts, etc.
// Each button toggles the state to show respective views or popups.
Spacer()
HStack{
HStack(alignment: .bottom, spacing: 28.0) {
Button{

}label:
Button(action: {updateARState.updateTrue = true})
{
Image(systemName: "map")
.foregroundColor(.white)
Expand Down

0 comments on commit 93e2e1e

Please sign in to comment.