diff --git a/demo.html b/demo.html new file mode 100644 index 0000000..908d92c --- /dev/null +++ b/demo.html @@ -0,0 +1,54 @@ + + + + + + + DMD 3440 - Room of Chat Demo + + + + + +
+
My profile pic: + + + Picture of me +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo.js b/demo.js new file mode 100644 index 0000000..48697f5 --- /dev/null +++ b/demo.js @@ -0,0 +1,59 @@ +// var initialMessages = getAllMessagesFromFirebase(); +// console.log(initialMessages); +var username = "Joel"; +var chatLog = document.querySelector("#chatLog"); +var inputBox = document.querySelector("#inputBox"); +var sendButton = document.querySelector("#sendButton"); +var profilePicInput = document.querySelector("#profilePic"); +var saveProfileButton = document.querySelector("#saveProfile"); +var profilePicDisplayElement = document.querySelector("#profilePicDisplay"); +var profilePic = localStorage.getItem("userProfilePic") || "unknown.jpg"; + +var testMessage = { + dateStamp:"983459835498345", + message: "Hello test!", + sentBy: "Joel" +} + +profilePicDisplayElement.src = profilePic; + +function saveProfileImageLocally() { + if (profilePicInput.files && profilePicInput.files[0]) { + var reader = new FileReader(); + reader.onload = function(e) { + localStorage.setItem("userProfilePic", reader.result); + } + reader.readAsDataURL(profilePicInput.files[0]); + } +} + +function displayMessage(message) { + var messageParagraph = document.createElement("p"); + messageParagraph.innerHTML = message.dateStamp + " " + message.message + " " + message.sentBy; + + chatLog.appendChild(messageParagraph); + chatLog.scrollTop = chatLog.scrollHeight; +} + +watchFirebaseForChanges( + function(msg){ + displayMessage(msg.data()) + } +); + +sendButton.addEventListener("click", function () { + var msgObj = { + dateStamp:Date.now(), + message: inputBox.value, + sentBy: username + } + + saveMessageToFirebase(msgObj); + + inputBox.value = ""; + inputBox.focus(); +}); + +saveProfileButton.addEventListener("click", function() { + saveProfileImageLocally(); +}); \ No newline at end of file diff --git a/firebase-chat-functions.js b/firebase-chat-functions.js index 65a98bb..f633293 100644 --- a/firebase-chat-functions.js +++ b/firebase-chat-functions.js @@ -26,4 +26,4 @@ function watchFirebaseForChanges(callBack) { //getAllMessagesFromFirebase(); -watchFirebaseForChanges(function(msg){displayNewMessage(msg.data())}) \ No newline at end of file +//watchFirebaseForChanges(function(msg){displayNewMessage(msg.data())}) \ No newline at end of file diff --git a/joel.jfif b/joel.jfif new file mode 100644 index 0000000..c41c56c Binary files /dev/null and b/joel.jfif differ