Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 52 additions & 25 deletions assets/javascript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ $(document).ready(() => {
var yelpSearch;
var currentLatitude;
var currentLongitude;
var user;

// Initialize Firebase ----------------------------------------
var config = {
Expand Down Expand Up @@ -155,7 +156,7 @@ $(document).ready(() => {
if (Math.floor(distance) !== 0) {
addShouterMarker(listenLoctation);
initiateYelp();

} //--end if

// Drop a pin if you find someoneTODO: MAY NEED IT FOR CLASS PRESENTATION
Expand All @@ -168,23 +169,24 @@ $(document).ready(() => {
}, errorData);

//check chat
chatRef.on("child_added", function (snapshot) {
if (snapshot.val()) {
var fireBaseMessage = snapshot.val().chatMessage;
console.log(fireBaseMessage);
console.log(snapshot.child("chatMessage"))
//message key
// var chatKey = chatMessage.key;

$(".chat-text ul").prepend(`<li class="message-font"> ${fireBaseMessage}</>`);
chatRef.onDisconnect().remove();
}
});
// chatRef.on("child_added", function (snapshot) {
// if (snapshot.val()) {
// var fireBaseMessage = snapshot.val().chatMessage;
// var messageUser = snapshot.val().user;
// console.log(fireBaseMessage);
// console.log(snapshot.child("chatMessage"))
// //message key
// var chatKey = chatMessage.key;

// $(".chat-text ul").prepend(`<li class="message-font">${messageUser}: ${fireBaseMessage}</>`);
// chatRef.onDisconnect().remove();
// }
// });

//---------------------------START functions--------------
function initiateYelp (){
//update yelp markers on all users
yelpRef.on("value", (snapshot) => {
function initiateYelp() {
//update yelp markers on all users
yelpRef.on("value", (snapshot) => {
var dataSnap = snapshot.val();
//convert lat and lng to strings
var stringLatF = dataSnap.center.lat.toString();
Expand All @@ -193,7 +195,7 @@ function initiateYelp (){
console.log("geting info");
getYelpInfo(dataSnap.search, stringLatF, stringLngF);
}, errorData);
}
}

function startYelpSearch(e) {
// e.preventDefault();
Expand Down Expand Up @@ -569,11 +571,11 @@ function initiateYelp (){

// display shout
shouterInfoWindow.open(map, marker);
//check if marker has been clicked
marker.addListener("click", () => {
//check if marker has been clicked
marker.addListener("click", () => {
displayChat();
});

//bounce animation
setTimeout(() => {
marker.setAnimation(google.maps.Animation.BOUNCE);
Expand All @@ -584,13 +586,33 @@ function initiateYelp (){
// chat functionality
function chatMessages(event) {
// event.preventDefault();
var chatMessage = $("#chatInput").val()
chatRef.push({
chatMessage: chatMessage
});
var chatMessage = chatRef.push({
chatMessage: $("#chatInput").val(),
user: user,
})

$("#chatInput").val("");
}

$("#shout").on("click", function (event) {
user = $('#shoutText').val();
usersRef.set(user);
})

chatRef.on("child_added", function (snapshot) {
if (snapshot.val()) {
var fireBaseMessage = snapshot.val().chatMessage;
var messageUser = snapshot.val().user;
console.log(fireBaseMessage);
console.log(snapshot.child("chatMessage"))
//message key
// var chatKey = chatMessage.key;

$(".chat-text ul").prepend(`<li class="message-font">${messageUser}: ${fireBaseMessage}</>`);
chatRef.onDisconnect().remove();
}
});

//check if threre is a shout
function checkShoutTextVal(shoutText) {
console.log("There is no value!");
Expand Down Expand Up @@ -621,13 +643,18 @@ function initiateYelp (){
markers = [];
}

function displayChat() {
$(".welcome-wrapper").css("display", "none");
$(".chat-wrapper").css("display", "block");
}

function clearMarkers() {
setMapOnAll(null);
}

//---------------

function displayChat() {
function displaym() {
$(".welcome-wrapper").css("display", "none");
$(".chat-wrapper").css("display", "block");
}
Expand Down