Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
final push
  • Loading branch information
yuh19027 committed May 6, 2020
1 parent 0fd66e4 commit 0ea6952
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 91 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 0 additions & 2 deletions final/css/main.css
Expand Up @@ -127,8 +127,6 @@ div:not(.Me) > span > p{
margin-top: 5px;
margin-right: 0;
background-color: #f9d861;
-moz-border-radius: 8px;
-moz-border-radius-topleft: 0;
border-radius: 8px;
border-top-left-radius: 0;
padding-left: 15px;
Expand Down
180 changes: 91 additions & 89 deletions final/js/main.js
@@ -1,17 +1,15 @@


// Register a service worker, this one located in serviceworker.js
// A service worker is a piece of code the browser runs behind the scenes.
if ('serviceWorker' in navigator) {
console.log('CLIENT: service worker registration in progress.');
navigator.serviceWorker.register('sw.js').then(function() {
console.log('CLIENT: service worker registration complete.');
}, function() {
console.log('CLIENT: service worker registration failure.');
});
} else {
console.log('CLIENT: service workers are not supported.');
}
console.log('CLIENT: service worker registration in progress.');
navigator.serviceWorker.register('sw.js').then(function() {
console.log('CLIENT: service worker registration complete.');
}, function() {
console.log('CLIENT: service worker registration failure.');
});
} else {
console.log('CLIENT: service workers are not supported.');
}



Expand All @@ -24,63 +22,67 @@ let inputBox = document.querySelector("#newmsg");
// pictureEndpoint.setAttribute("src",localStorage.userProfilePic)


let curr_date = new Date();
let month = curr_date.getMonth() + 1;
let dateStr = month.toString() + "/" + curr_date.getDate().toString() + "/" + curr_date.getFullYear().toString();


let realTime = new Date();
let hours = realTime.getHours();
let minutes = realTime.getMinutes();

//Add AM and PM system
let amPm = (hours < 12 ) ? "AM" : "PM";
//convert the hours component to 12-hour format
hours = (hours > 12) ? hours - 12 : hours;
//pad the hours, minutes and seconds with leading zeros
hours = ("0" + hours).slice(-2);
minutes = ("0" + minutes).slice(-2);
let timeStr = hours + ":" + minutes + " " + amPm;

// //Display the time
// document.getElementById('clock').innerHTML =
// hours + " : " + minutes + " " + amPm;
// var t = setTimeout(displayTime, 500);


// //Display the time
// document.getElementById('clock').innerHTML =
// hours + " : " + minutes + " " + amPm;

// }

function makeMessage(msg) {

var stagedMessage = document.createElement("div");
var inLineContainer = document.createElement("span");
var name = document.createElement("h2");

var message = document.createElement("p");
var timeStamp = document.createElement("h4");

let curr_date = new Date(msg.dateStamp);
let month = curr_date.getMonth() + 1;
let dateStr = month.toString() + "/" + curr_date.getDate().toString() + "/" + curr_date.getFullYear().toString();


let realTime = new Date(msg.dateStamp);
let hours = realTime.getHours();
let minutes = realTime.getMinutes();

//Add AM and PM system
let amPm = (hours < 12 ) ? "AM" : "PM";
//convert the hours component to 12-hour format
hours = (hours > 12) ? hours - 12 : hours;
//pad the hours, minutes and seconds with leading zeros
hours = ("0" + hours).slice(-2);
minutes = ("0" + minutes).slice(-2);
let timeStr = hours.toString() + ":" + minutes.toString() + " " + amPm;
console.log(timeStr)

if(msg.sentBy == localStorage.userName){
stagedMessage.setAttribute("class", "Me");
}

inLineContainer.setAttribute("class", "people");

var stagedMessage = document.createElement("div");
var inLineContainer = document.createElement("span");
var name = document.createElement("h2");

var message = document.createElement("p");
var timeStamp = document.createElement("h4");

if(msg.sentBy == localStorage.userName){
stagedMessage.setAttribute("class", "Me");
}

inLineContainer.setAttribute("class", "people");


name.innerHTML=msg.sentBy;
timeStamp.innerHTML=timeStr + " " + dateStr;
message.innerHTML=msg.message;


inLineContainer.appendChild(name);
inLineContainer.appendChild(timeStamp);

stagedMessage.appendChild(inLineContainer);
inLineContainer.appendChild(message);
chatBox.appendChild(stagedMessage);
stagedMessage.scrollIntoView();
//allMessages.push(newMessage);


console.log(allMessages);

name.innerHTML=msg.sentBy;
timeStamp.innerHTML=timeStr + " " + dateStr;
message.innerHTML=msg.message;


inLineContainer.appendChild(name);
inLineContainer.appendChild(timeStamp);

stagedMessage.appendChild(inLineContainer);
inLineContainer.appendChild(message);
chatBox.appendChild(stagedMessage);
stagedMessage.scrollIntoView();
//allMessages.push(newMessage);


console.log(allMessages);
}


Expand All @@ -89,47 +91,47 @@ function makeMessage(msg) {


document.querySelector("#sendBtn").addEventListener('click', () => {
let msg = document.querySelector("#newmsg").value;
let src = "notification.mp3"
let audio = new Audio(src);
audio.play();
let msg = document.querySelector("#newmsg").value;
let src = "notification.mp3"
let audio = new Audio(src);
audio.play();

document.querySelector("#newmsg").value = "";
document.querySelector("#newmsg").focus();
document.querySelector("#newmsg").value = "";
document.querySelector("#newmsg").focus();




let userMsg = {
sentBy: localStorage.userName,
dateStr: month.toString() + "/" + curr_date.getDate().toString() + "/" + curr_date.getFullYear().toString(),
// timeStr: curr_time.getHours().toString() + ":" + curr_time.getMinutes().toString(),
timeStamp: msg.timeStr + " " + msg.dateStr,
message: msg
let userMsg = {
sentBy: localStorage.userName,
dateStr: month.toString() + "/" + curr_date.getDate().toString() + "/" + curr_date.getFullYear().toString(),
// timeStr: curr_time.getHours().toString() + ":" + curr_time.getMinutes().toString(),
timeStamp: msg.timeStr + " " + msg.dateStr,
message: msg

}
if (localStorage.userName != undefined) {
saveMessageToFirebase(userMsg);
} else {
alert("Set a Username");
}

}
if (localStorage.userName != undefined) {
saveMessageToFirebase(userMsg);
} else {
alert("Set a Username");
}

inputBox.value = "";
inputBox.focus();

console.log(new_message);
window.navigator.vibrate(200);
inputBox.value = "";
inputBox.focus();

console.log(new_message);
window.navigator.vibrate(200);


//makeMessage("Me", date_str, msg,localStorage.userName);

//makeMessage("Me", date_str, msg,localStorage.userName);

});



watchFirebaseForChanges(
function(msg){
makeMessage(msg.data())
}
function(msg){
makeMessage(msg.data())
}
);

0 comments on commit 0ea6952

Please sign in to comment.