Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evelyn #23

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
65b7a9a
learnings on July 23 2021
Jul 24, 2021
0e96e2f
learnings on July 26th, 2021
Jul 27, 2021
fe7b323
the dom
Jul 28, 2021
e4f10c1
chapter 6 finished learning
Jul 30, 2021
9a6d1e1
chapter 7 form & form events
Jul 30, 2021
69594b3
created a Ninja quiz
Jul 30, 2021
bf95c7a
practiced once
Jul 30, 2021
6cb9391
practice twice
Jul 30, 2021
2ce66ef
switching computer
Evelyn-ZYW Aug 30, 2021
3fb03a1
chapter 9 learnings
Evelyn-ZYW Aug 30, 2021
a217b0b
learnings of the mini project - todos
Evelyn-ZYW Aug 31, 2021
5132337
understanding Async in a very basic level
Evelyn-ZYW Sep 3, 2021
fe7c3eb
understanding HTTP request & JSON
Evelyn-ZYW Sep 3, 2021
d7aef64
understanding promises and how to use it in a request
Evelyn-ZYW Sep 3, 2021
5387bb0
chain promises together
Evelyn-ZYW Sep 3, 2021
933384b
understanding fetch() and async & await
Evelyn-ZYW Sep 4, 2021
e0acc1d
understanding throwing & catching errors
Evelyn-ZYW Sep 4, 2021
e0ee6fd
object shorthand notation
Evelyn-ZYW Sep 16, 2021
e5095a2
get reference of the card and details elements
Evelyn-ZYW Sep 16, 2021
1006f26
created updateUI function to receive the data from updateCity functio…
Evelyn-ZYW Sep 16, 2021
d6eedbc
destructuring - an easy way to get properties from an object and stor…
Evelyn-ZYW Sep 16, 2021
b9788f2
get references of the time and icon elements; added icons and imgs
Evelyn-ZYW Sep 16, 2021
7fe227c
use Ternary Operator instead of regular if elase statement
Evelyn-ZYW Sep 16, 2021
909dbfe
localStorage: 1. setItem 2. getItem 3. removeItem 4. clear
Evelyn-ZYW Sep 19, 2021
819ef71
localStorage for the weather app
Evelyn-ZYW Sep 19, 2021
2917f35
class inheritance
Evelyn-ZYW Sep 21, 2021
9f20336
constructor inheritance & super()
Evelyn-ZYW Sep 21, 2021
4fa64fb
prototype model
Evelyn-ZYW Sep 21, 2021
73bae52
prototypal inheritance
Evelyn-ZYW Sep 21, 2021
aa543a1
making a Forecast class for the weather app
Evelyn-ZYW Sep 21, 2021
c2c7415
firebase
Evelyn-ZYW Sep 22, 2021
cf00bfc
deleted node_modules folder
Evelyn-ZYW Sep 22, 2021
72355b6
real-time listeners enable real-time update to the UI when adding or …
Evelyn-ZYW Sep 22, 2021
317f8e4
unsubscribe from the collection changes
Evelyn-ZYW Sep 22, 2021
1430167
cleared some unused files and codes
Evelyn-ZYW Sep 22, 2021
cada1e3
real-time chatroom done
Evelyn-ZYW Oct 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
real-time listeners enable real-time update to the UI when adding or …
…deleting data from the firestore database
  • Loading branch information
Evelyn-ZYW committed Sep 22, 2021
commit 72355b6c0d392b540121468cd36d6f018d43a18e
28 changes: 19 additions & 9 deletions chapter_16_databases/sandbox1.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,26 @@ const addRecipe = (recipe, id) => {
list.innerHTML += html
}

// get document
db.collection('recipes').get().then(snapshot => {
//when we have the data
snapshot.docs.forEach(doc => {
// console.log(doc.id)
addRecipe(doc.data(), doc.id)
const deleteRecipe = (id) => {
const recipes = document.querySelectorAll('li')
recipes.forEach(recipe => {
if(recipe.getAttribute('data-id') === id){
recipe.remove()
}
})
}).catch(err => {
console.log(err)
})
}

// get document - Real-time Listeners
db.collection('recipes').onSnapshot(snapshot => {
snapshot.docChanges().forEach(change => {
const doc = change.doc
if(change.type === 'added'){
addRecipe(doc.data(), doc.id)
} else if(change.type === 'removed'){
deleteRecipe(doc.id)
}
})
});

// add document
form.addEventListener('submit', e => {
Expand Down