Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
230 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function saveMessageToFirebase(msg) { | ||
db.collection("messages").add(msg) | ||
} | ||
|
||
function getAllMessagesFromFirebase() { | ||
let allMsgs = []; | ||
db.collection("messages").orderBy('dateStamp', 'asc').limit(200).get().then(function(querySnapshot) { | ||
querySnapshot.forEach(function(doc) { | ||
// doc.data() is never undefined for query doc snapshots | ||
allMsgs.push(doc.data()) | ||
}); | ||
}); | ||
|
||
return allMsgs; | ||
} | ||
|
||
function watchFirebaseForChanges(callBack) { | ||
db.collection("messages").orderBy('dateStamp','asc').onSnapshot(function(querySnapshot) { | ||
querySnapshot.docChanges().forEach(function(change) { | ||
if (change.type === "added") { | ||
callBack(change.doc); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
|
||
//getAllMessagesFromFirebase(); | ||
//watchFirebaseForChanges(function(msg){displayNewMessage(msg.data())}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var firebaseConfig = { | ||
apiKey: "AIzaSyAbh39Rb-F9_PO8lpAoob_qA1dYUVNYAkg", | ||
authDomain: "dmd-3440-pwa-demo.firebaseapp.com", | ||
databaseURL: "https://dmd-3440-pwa-demo.firebaseio.com", | ||
projectId: "dmd-3440-pwa-demo", | ||
storageBucket: "dmd-3440-pwa-demo.appspot.com", | ||
messagingSenderId: "239477441112", | ||
appId: "1:239477441112:web:0dcd3f94fe067b09ac402d" | ||
}; | ||
// Initialize Firebase | ||
firebase.initializeApp(firebaseConfig); | ||
var db = firebase.firestore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
let usernameInput = document.querySelector("#usernameInput"); | ||
let statusInput = document.querySelector("#statusInput"); | ||
let profilePicInput = document.querySelector("#profilePicInput"); | ||
let profileSaveInput = document.querySelector("#profileSaveInput"); | ||
|
||
// setting the input values default | ||
usernameInput.value = localStorage.getItem('userName'); | ||
statusInput.value = localStorage.getItem('userStatus'); | ||
userProfilePicDisplay.value = localStorage.getItem('profilePicInput') | ||
|
||
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]); | ||
} | ||
} | ||
|
||
profileSaveInput.addEventListener( 'click', function(e) { | ||
e.preventDefault(); | ||
localStorage.setItem("userName", usernameInput.value); | ||
localStorage.setItem("userStatus", statusInput.value); | ||
|
||
saveProfileImageLocally(); | ||
}); | ||
usernameDisplay.innerHTML = userName; | ||
userStatusDisplay.innerHTML = userStatus; | ||
userProfilePicDisplay.src = userProfilePic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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.'); | ||
} |