From 5060280e2ce1b2e98d2583919bfdec765f64dd87 Mon Sep 17 00:00:00 2001 From: AlineMussi Date: Thu, 17 Oct 2019 15:43:55 -0300 Subject: [PATCH] feed com funcao storage, salvando post no banco de dados Firestorage --- src/pages/feed.js | 57 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/src/pages/feed.js b/src/pages/feed.js index b6aaa2bf4..d77ba8d9c 100644 --- a/src/pages/feed.js +++ b/src/pages/feed.js @@ -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 = `

Rede Social

-

Esse é um exemplo 🍌

- `; + ${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 = `
  • + ${post.data().text} +
  • + ` + 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; \ No newline at end of file