From 9f94efea9eaedf01954dcbd5565d503bf7a6eb80 Mon Sep 17 00:00:00 2001 From: Yucheng Hang Date: Tue, 10 Mar 2020 15:01:14 -0400 Subject: [PATCH] 03/09 --- main.css | 21 ++++++++++++--------- main.js | 19 ++++++++++++++++++- profile.js | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/main.css b/main.css index b5515aa..5763120 100644 --- a/main.css +++ b/main.css @@ -16,22 +16,25 @@ header{ #chatBox { - width:100%; - position:absolute; - bottom:70px; - top:80px; - right:0px; - left:0px; + width: 100vw; + position: absolute; + bottom: 70px; + top: 80px; + right: 0px; + left: 0px; + overflow: scroll; background:#fff; - color:#000; padding:15px; + } + + #chatInput { position:fixed; left:0px; - bottom:0; + bottom:0; width:100%; background-color:#eee; display: flex; @@ -74,4 +77,4 @@ header p{ height: 40px; border-radius: 50px; text-align: center;; -} \ No newline at end of file +} diff --git a/main.js b/main.js index b677e40..7a1cff1 100644 --- a/main.js +++ b/main.js @@ -22,6 +22,7 @@ if ('serviceWorker' in navigator) { let usernameDisplay = document.querySelector("#usernameDisplay"); let userStatusDisplay = document.querySelector("#userStatusDisplay"); let userProfilePicDisplay = document.querySelector("#userProfilePicDisplay"); + let sendButton = document.querySelector("#sendBtn") usernameDisplay.innerHTML = userName; @@ -61,7 +62,11 @@ if ('serviceWorker' in navigator) { saveMessageToFirebase(usrMsg); } } - + watchFirebaseForChanges( + function(msg){ + displayNewMessage(msg.data()) + } +); /** All the triggers and event listener assignments down here... */ // assign the "Make New Message" function to the button click @@ -95,4 +100,16 @@ if ('serviceWorker' in navigator) { userName = localStorage.getItem("userName"); }); + sendButton.addEventListener("click", function () { + var msgObj = { + dateStamp:Date.now(), + message: inputBox.value, + sentBy: username + } + + saveMessageToFirebase(msgObj); + + inputBox.value = ""; + inputBox.focus(); +}); diff --git a/profile.js b/profile.js index 81e2696..43a7db8 100644 --- a/profile.js +++ b/profile.js @@ -19,6 +19,22 @@ function saveProfileImageLocally() { } } +//set button colors when click +/* var count = 1; + function setColor(btn, color) { + var property = document.getElementById("profileSaveInput"); + if (count == 0) { + property.style.backgroundColor = "#f9d861" + count = 1; + } + else { + property.style.backgroundColor = "#3e2fae" + count = 0; + } + } */ + + + profileSaveInput.addEventListener( 'click', function(e) { e.preventDefault(); localStorage.setItem("userName", usernameInput.value);