Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
firebase and stuff
- Loading branch information
Joel Salisbury
committed
Mar 3, 2020
1 parent
5275a9f
commit 8cd0e6c
Showing
9 changed files
with
179 additions
and
40 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
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,14 @@ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="theme-color" content="#f00" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Edit Profile</title> | ||
<link href="main.css?version=2" rel="stylesheet"> | ||
<link rel="manifest" href="manifest.json?version=2"> | ||
</head> | ||
<body> | ||
|
||
<header><a href="index.html">Back</a><h1>Edit Profile</h1></header> | ||
|
||
<div> | ||
<p><input type="text" placeholder="Display Name" name="UserName" id="usernameInput"></p> | ||
<p><input type="text" placeholder="Status Message" name="StatusMessage" id="statusInput"></p> | ||
<p><input type="file" id="profilePicInput" name="profilePicInput"></p> | ||
<button id="profileSaveInput">Save Profile</button> | ||
</div> | ||
|
||
<!-- Firebase App (the core Firebase SDK) is always required and must be listed first --> | ||
<script src="https://www.gstatic.com/firebasejs/7.9.2/firebase-app.js"></script> | ||
|
||
<!-- If you enabled Analytics in your project, add the Firebase SDK for Analytics --> | ||
<script src="https://www.gstatic.com/firebasejs/7.9.2/firebase-analytics.js"></script> | ||
|
||
<!-- Add Firebase products that you want to use --> | ||
<script src="https://www.gstatic.com/firebasejs/7.9.2/firebase-auth.js"></script> | ||
<script src="https://www.gstatic.com/firebasejs/7.9.2/firebase-firestore.js"></script> | ||
<script src="firebase-config.js"></script> | ||
<script src="register-sw.js"></script> | ||
|
||
<script src="profile.js?version=2"></script> | ||
</body> | ||
</html> |
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'); | ||
|
||
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(); | ||
}); | ||
|
||
|
||
|
||
|
||
|
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.'); | ||
} |
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