forked from Laboratoria/SAP003-social-network
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feed com funcao storage, salvando post no banco de dados Firestorage
- Loading branch information
1 parent
0351c4c
commit 5060280
Showing
1 changed file
with
54 additions
and
3 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 |
---|---|---|
@@ -1,9 +1,60 @@ | ||
/* eslint-disable indent */ | ||
import Button from '../components/button.js'; | ||
import Input from '../components/input.js'; | ||
import Div from '../components/div.js'; | ||
//import Div from '../components/div.js'; | ||
//import Card from '../components/card.js'; | ||
|
||
function Feed() { | ||
const template = ` | ||
const template = ` | ||
<h1>Rede Social</h1> | ||
<p>Esse é um exemplo 🍌</p> | ||
`; | ||
${Input({ | ||
class: 'post-input', | ||
type: 'text' | ||
}) + | ||
Button({ | ||
title: 'enviar', | ||
onClick: loadData | ||
}) + | ||
Div({ | ||
class: 'insert-post' | ||
})}`; | ||
|
||
return template; | ||
} | ||
|
||
|
||
function loadData() { | ||
const postlist = document.querySelector('.post-input').value; | ||
//cria coleção de post no firebase/ ''post' representa o objeto que será criado no banco de dados firebase storage | ||
firebase.firestore().collection('post').add({ | ||
text: postlist, | ||
userID: firebase.auth().currentUser.uid, | ||
//método JS para pegar a data | ||
addeAt: (new Date()).toISOString(), | ||
}).then(result => alert('oi')) | ||
document.querySelector ('insert-post').innerHTML = text; | ||
} | ||
|
||
function addPost(post) { | ||
const postTemplate = `<li> | ||
${post.data().text} | ||
</li> | ||
` | ||
document.querySelector('.insert-post').innerHTML += postTemplate; | ||
} | ||
|
||
const loadPost = () => { | ||
const postCollection = firebase.firestore().collection('post'); | ||
postCollection.get().then(snap => { | ||
snap.forEach(post => { | ||
addPost(post) | ||
}) | ||
}) | ||
} | ||
|
||
|
||
loadPost() | ||
|
||
|
||
export default Feed; |