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

postagens sendo exibidas com printar post #16

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 19 additions & 13 deletions src/lib/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function redefinirSenha(email) {

export async function adicionarPost(username, conteudo) {
try {

const docRef = await addDoc(collection(db, "posts"), {
username: auth.currentUser.displayName,
uid: auth.currentUser.uid,
Expand All @@ -52,17 +53,22 @@ export async function adicionarPost(username, conteudo) {

export async function exibirPosts() {
try {
const feedElement = document.querySelector('.post');
const querySnapshot = await getDocs(collection(db, "posts"));
querySnapshot.forEach((doc) => {
const post = doc.data();
const postElement= document.createElement('div');
postElement.innerHTML = `<h2>${post.username}</h2>
<p>${post.conteudo}</p>`;
feedElement.appendChild(postElement);
console.log(`teste1 ${doc.id} => ${doc.data()}`);
});
} catch (error) {
console.error('erro ao obter os posts', error);
}
const querySnapshot = await getDocs(collection(db, "posts"));
const feedElement = document.querySelector('.post');
feedElement.innerHTML = '';
const array = [];
querySnapshot.forEach((doc) => {
// const post = doc.data();
// const postElement = document.createElement('div');
// postElement.innerHTML = `<h2>${post.username}</h2>
// <p>${post.conteudo}</p>
// <hr>`;
// feedElement.appendChild(postElement);
array.push(doc.data());
// console.log(`${doc.id} => ${doc.data()}`);
});
return array;
} catch (error) {
console.error('erro ao obter os posts', error);
}
};
4 changes: 2 additions & 2 deletions src/pages/cadastro/cadastro.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export default () => {

checkBtn.addEventListener('change', mostrarSenha);

const mensagemFormatada = document.createElement('p');

botaoCadastrar.addEventListener('click', (event) => {
event.preventDefault();
const emailDoUsuario = inputEmail.value;
const senhaDoUsuario = inputSenha.value;
const nomeDoUsuario = inputNome.value;
const caixaDeTexto = container.querySelector('#caixaDeTexto');

const mensagemFormatada = document.createElement('p');

function exibirErro(errorCode) {
const mensagemErroDiv = document.getElementById('mensagemErro');
mensagemFormatada.textContent = `${errorCode}`;
Expand Down
1 change: 1 addition & 0 deletions src/pages/feed/feed.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
z-index: 2;
position: fixed;
width: 100vw;
display: none;
}

.lista-menu-mobile > li {
Expand Down
38 changes: 32 additions & 6 deletions src/pages/feed/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,41 @@ export default () => {

const btnPublicar = container.querySelector('#btn-publicar');
const textarea = container.querySelector('#story');
const post = container.querySelector('.post');
const textareaVal = textarea.value;
console.log(textareaVal);

// document.addEventListener('load', exibirPosts);
exibirPosts() // pega todos os docs ja criados e exibe na tela, como uma array de objetos // se os dados do post forem pegos, printa o post na tela.
.then((array) => {
printarPost(username, textareaVal);
console.log(array);
return array;
});

function printarPost(username, conteudo) { // cria um elemento div, adiciona no elemento div um h2 e p, adiciona esse conjunto
const postElement = document.createElement('div'); // dentro da div post e exibe na tela
postElement.innerHTML = `
<h2>${username}</h2>
<p>${conteudo}</p>
<hr>
`;
const feedElement = document.querySelector('.post');
feedElement.appendChild(postElement);
}

btnPublicar.addEventListener('click', () => {
const conteudoDoPost = document.createElement('p');
conteudoDoPost.textContent = textarea.value;
post.appendChild(conteudoDoPost);
adicionarPost(username, conteudoDoPost.textContent);
// const conteudoDoPost = document.createElement('p');
// conteudoDoPost.textContent = textarea.value;
// post.appendChild(conteudoDoPost);
const texto = textarea.value;
adicionarPost(username, texto) // cria uma collection com username e texto. se o doc for criado com sucesso, printa o post na tela

.then((banana) => {
printarPost(username, texto);
console.log(banana);
})
// salvarPost(username, conteudoDoPost.textContent);
textarea.value = '';
window.onload = exibirPosts();
})

return container;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ export default () => {
window.location.hash = '#redefinir-senha';
});

const mensagemFormatada = document.createElement('p');

botaoEntrar.addEventListener('click', (event) => {
event.preventDefault();
const emailDoUsuario = inputEmail.value;
const senhaDoUsuario = inputSenha.value;

const mensagemFormatada = document.createElement('p');

function exibirErro(errorCode) {
const mensagemErroDiv = document.getElementById('mensagemErro');
Expand Down