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

Dev marta #25

Open
wants to merge 92 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
0b15e47
probando css
FernandaFloresC Jun 18, 2022
1e00a70
Merge pull request #1 from MartaHung/DevFer
MartaHung Jun 20, 2022
6b9d449
templaate test
MartaHung Jun 20, 2022
598cffc
Merge pull request #2 from MartaHung/devMarta
MartaHung Jun 20, 2022
51fe488
agregamos los templates y routes de prueba
FernandaFloresC Jun 20, 2022
3ab288d
Merge pull request #3 from MartaHung/DevFer
MartaHung Jun 20, 2022
3f666a1
tz
MartaHung Jun 20, 2022
bc04251
m
MartaHung Jun 20, 2022
a49900f
gradiente rosa con meme
FernandaFloresC Jun 20, 2022
08e7448
templates, intento de rutas
MartaHung Jun 30, 2022
6ba5ad7
templates separados
MartaHung Jun 30, 2022
3dc2c0f
Merge pull request #4 from MartaHung/devMarta
MartaHung Jun 30, 2022
a166f15
se agrega base de las funciones para enrutar y cambiar de ruta y la f…
MartaHung Jul 4, 2022
5ea3b14
Merge pull request #5 from MartaHung/devMarta
MartaHung Jul 4, 2022
279c322
error de visual
FernandaFloresC Jul 4, 2022
5e2f4e9
Merge branch 'devMarta' of https://github.com/MartaHung/SCL020-social…
FernandaFloresC Jul 4, 2022
655a6c4
rama kathy
KatherineGalleguillos Jul 4, 2022
d0280ac
Merge pull request #6 from MartaHung/devkathy
MartaHung Jul 4, 2022
96ec552
actualizacion
MartaHung Jul 4, 2022
66dcf23
Merge pull request #7 from MartaHung/devMarta
MartaHung Jul 4, 2022
159e66a
KatherineGalleguillos Jul 4, 2022
518c3c9
Merge branch 'devkathy' of https://github.com/MartaHung/SCL020-social…
FernandaFloresC Jul 4, 2022
7bc79ce
init
KatherineGalleguillos Jul 4, 2022
47826db
Merge pull request #8 from MartaHung/devMarta
MartaHung Jul 4, 2022
ca5661e
router
KatherineGalleguillos Jul 4, 2022
819653f
error 2Â
FernandaFloresC Jul 4, 2022
b7659a4
Merge branch 'main' of https://github.com/MartaHung/SCL020-social-net…
FernandaFloresC Jul 4, 2022
e9fdbf7
router
KatherineGalleguillos Jul 4, 2022
9c08131
rutas funcionales
MartaHung Jul 6, 2022
877faf6
rutas router
MartaHung Jul 6, 2022
00f6d0c
Merge pull request #9 from MartaHung/devMarta
MartaHung Jul 6, 2022
43faad0
agregÃuÃé images a carpeta
FernandaFloresC Jul 6, 2022
b868bb2
auth google en proceso
MartaHung Jul 7, 2022
1bd096d
Merge pull request #11 from MartaHung/devMarta
MartaHung Jul 7, 2022
f741cae
template feed
MartaHung Jul 8, 2022
97cad48
Merge pull request #12 from MartaHung/devMarta
MartaHung Jul 8, 2022
ec64002
vistas e img de prueba
FernandaFloresC Jul 8, 2022
2d46672
Merge pull request #13 from MartaHung/DevFer
MartaHung Jul 8, 2022
b14e159
teest
MartaHung Jul 8, 2022
74fddf0
Delete config.js
MartaHung Jul 8, 2022
a902c08
cambios de css en 1vista
FernandaFloresC Jul 8, 2022
6eb0474
configuracion firestore, modificacion configuracion firebase, organiz…
MartaHung Jul 8, 2022
c4fd223
Merge pull request #14 from MartaHung/DevFer
MartaHung Jul 8, 2022
9d729c4
Merge pull request #15 from MartaHung/devMarta
MartaHung Jul 8, 2022
fe67121
Merge branch 'devMarta' of https://github.com/MartaHung/SCL020-social…
FernandaFloresC Jul 8, 2022
1887235
Merge branch 'DevFer' of https://github.com/MartaHung/SCL020-social-n…
MartaHung Jul 8, 2022
7ca1a36
template post y funciones para manipular data y crear posts
MartaHung Jul 11, 2022
1dce1df
Merge branch 'main' of https://github.com/MartaHung/SCL020-social-net…
FernandaFloresC Jul 11, 2022
241b311
ramapruebakathy
KatherineGalleguillos Jul 12, 2022
6949a06
ni idea del commit
FernandaFloresC Jul 12, 2022
12e5317
boton
KatherineGalleguillos Jul 12, 2022
5bf7d64
Merge branch 'main' into pruebakathy
MartaHung Jul 12, 2022
2893828
Merge pull request #16 from MartaHung/pruebakathy
MartaHung Jul 12, 2022
350c555
no veo nada :c
FernandaFloresC Jul 12, 2022
bfb02b9
funciones posts
MartaHung Jul 12, 2022
3ed5040
correcciones
MartaHung Jul 12, 2022
0e0b4e6
funciones para los posts, crear, editar y eliminar.
MartaHung Jul 12, 2022
c3f4d16
conflictos resueltos
MartaHung Jul 12, 2022
fb65a6b
cambios kathy
KatherineGalleguillos Jul 12, 2022
dd096da
bajando cambios de marta
FernandaFloresC Jul 12, 2022
fb7e204
bajando cambios de kathy
FernandaFloresC Jul 12, 2022
cd7b62d
subiendo cambios para probar
FernandaFloresC Jul 12, 2022
524c083
actualizacion
MartaHung Jul 13, 2022
dd69d38
subiendo cambios de oh
FernandaFloresC Jul 13, 2022
e169e90
actualizacion
MartaHung Jul 13, 2022
911e34c
test
MartaHung Jul 13, 2022
07f34ea
se rompio el code
MartaHung Jul 13, 2022
15ead35
cambios de tarde con Dani
FernandaFloresC Jul 13, 2022
701c88f
cambios que muestran la primera vista
FernandaFloresC Jul 13, 2022
7b1b654
codigo roto pero sin error
MartaHung Jul 13, 2022
a1d2ae0
nada funciona
MartaHung Jul 13, 2022
c6fb557
cambios leves para que se vea la vista
FernandaFloresC Jul 13, 2022
6782100
no se ven creaciones
MartaHung Jul 14, 2022
9c99dd7
estilo
MartaHung Jul 14, 2022
58528d5
ggg
MartaHung Jul 14, 2022
6d8148b
pequeños cambios
KatherineGalleguillos Jul 14, 2022
507b3cd
funciona login, y router, falta indexar el user al post, por eso no s…
MartaHung Jul 14, 2022
e1e2e4f
nada que subir, solo errores
FernandaFloresC Jul 14, 2022
37c0075
codigo funcionando, actualizado. Hay que arreglar funciones de guarda…
MartaHung Jul 15, 2022
f20aef8
actualizado
MartaHung Jul 15, 2022
c4e1b2a
actualizacion
MartaHung Jul 15, 2022
b374b5e
commit de mentiras
FernandaFloresC Jul 15, 2022
7426b54
test
MartaHung Jul 15, 2022
c1c1e8e
modificaciones css
KatherineGalleguillos Jul 15, 2022
b976376
viendo lo del observador
MartaHung Jul 15, 2022
474355e
merging
MartaHung Jul 15, 2022
c95132d
cambios de css en primera vista final
FernandaFloresC Jul 15, 2022
08a19e2
test
MartaHung Jul 15, 2022
02ff41a
merge
MartaHung Jul 15, 2022
c063d45
ahora se puede editar
MartaHung Jul 16, 2022
368e8d4
actualizacion, guarda id de usuario en firestore
MartaHung Jul 18, 2022
6b7e6cf
funcion logout y creacion de coleccion de usuarios
MartaHung Jul 18, 2022
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
coverage/
node_modules/
.yarn.lock
package-lock.json
package-lock.json
src/firebase/config.js
519 changes: 0 additions & 519 deletions README.md

Large diffs are not rendered by default.

Binary file added src/images/deformitoLlorando.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/deformitoTierno.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/deformitoTip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/deformitoTriste.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/error.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/fondo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<title>Tips para el Adulto Independiente</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="root"></div>
<div id="rootPost"></div>

<script type="module" src="main.js"></script>
</body>
</html>
</html>
76 changes: 76 additions & 0 deletions src/lib/firebase/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
auth,
provider,
signInWithPopup,
doc, db,
setDoc, getDoc, signOut
} from "./init.js";


export const loginGoogle = () => {

const btnGoogle = document.querySelector('.logIn');
btnGoogle.addEventListener('click', (event) => {
event.preventDefault();

loginWithGoogle();
});
};



export const loginWithGoogle = () => {
signInWithPopup(auth, provider)
.then((result) => {
// This gives you a Google Access Token. You can use it to access the Google API.
//const credential = GoogleAuthProvider.credentialFromResult(result);
//const token = credential.accessToken;
// The signed-in user info.
const user = result.user;
const userFirestore = setDoc(doc(db, "users", user.uid),{
name : user.displayName,
email: user.email
});
console.log(user);
console.log(userFirestore);
window.location.href = "#/feed";
})
.catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
//const email = error.customData.email;
// The AuthCredential type that was used.
//const credential = GoogleAuthProvider.credentialFromError(error);
// ...
console.log()
});


}



export const logOut = () => {
signOut(auth).then(() => {
// Sign-out successful.
console.log('log out')
console.log(currentUser());
}).catch((error) => {
console.log(error);
// An error happened.
});
};

//console.log(logOut(auth));

// export const getUser = async (id) => {
// try {
// const data = doc(db, 'users', id);
// const userData = await getDoc(data);
// return userData.data();
// } catch (err) {
// console.log(err);
// }
// };
9 changes: 9 additions & 0 deletions src/lib/firebase/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Your web app's Firebase configuration
export const firebaseConfig = {
apiKey: "AIzaSyBBsF0xI43K_mjmI_NUtb01CE4BApx7u2A",
authDomain: "adultoindependiente-4f40c.firebaseapp.com",
projectId: "adultoindependiente-4f40c",
storageBucket: "adultoindependiente-4f40c.appspot.com",
messagingSenderId: "525789460084",
appId: "1:525789460084:web:69113ad92df61afaef8321"
};
32 changes: 32 additions & 0 deletions src/lib/firebase/firestore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//funciones firestore
import { db, collection, addDoc, onSnapshot, doc, getDoc, deleteDoc, updateDoc } from "./init.js";


//Función que guarda los datos del formulario del post en firebase
export const savePost = ( title, text) => {

//Agrega un doc a una colección en formato de objeto
addDoc(collection(db,'posts'),{title:title, text:text});
//console.log(collection(db,'posts'),{autor:autor, title:title, text:text});
};


//obtiene los docs en tiempo real
export const onGetPost = (callback) => onSnapshot(collection(db, "posts"), callback);
//console.log(onGetPost());



export const editPost = (id) => {
const postRef = getDoc(doc(db,'posts',id));
return postRef;
};

export const deletePost = (id) => {
const delDocRef = deleteDoc(doc(db,'posts',id))
return delDocRef;
};

export const updatePost = (id, {title:title, text:text}) => {
updateDoc(doc(db,'posts',id), {title:title, text:text});
};
30 changes: 30 additions & 0 deletions src/lib/firebase/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

//Conexión con Firebase
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.8.4/firebase-app.js'
//configuracion firebase
import { firebaseConfig } from './config.js';
//Importando funciones firebase auth
import { getAuth, signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, onAuthStateChanged, signOut } from 'https://www.gstatic.com/firebasejs/9.8.4/firebase-auth.js';
//Importando funciones relacionadas a firestore
import { getFirestore, collection, getDocs, addDoc,onSnapshot, query, doc, getDoc, deleteDoc, updateDoc, setDoc } from 'https://www.gstatic.com/firebasejs/9.8.4/firebase-firestore.js';



// Initialize Firebase
const app = initializeApp(firebaseConfig);

//Autenticación
const auth = getAuth();

//Provider
const provider = new GoogleAuthProvider();

// Get firestore
const db = getFirestore(app);




//Exportar funciones firebase-firestore
export { initializeApp, signInWithEmailAndPassword, auth, signInWithPopup, provider, GoogleAuthProvider, collection, getDocs, addDoc,onSnapshot, query, doc, db, deleteDoc, getDoc, onAuthStateChanged, updateDoc, setDoc, signOut };

6 changes: 0 additions & 6 deletions src/lib/index.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/lib/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { menuLogin } from './views/templateMenu.js';
import { feed } from './views/templateFeed.js';
import { loginGoogle } from './firebase/auth.js';


export const changeRoutes = (hash) => {
const containerRoot = document.getElementById('root');
//containerRoot.innerHTML = "";
switch (hash){
case '#/menuLogin':
containerRoot.appendChild(menuLogin());
loginGoogle();

break;
case '#/feed':
containerRoot.appendChild(feed());

break;
default:
containerRoot.innerHTML= `<h2> Error (╯°□°)╯︵ ┻━┻ </h2>`
};
};



134 changes: 134 additions & 0 deletions src/lib/views/templateFeed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { logOut } from "../firebase/auth.js";
import {
savePost,
deletePost,
editPost,
onGetPost,
updatePost,
} from "../firebase/firestore.js";
import { auth } from "../firebase/init.js";

//Muro de la red
export const feed = () => {

const divFeed = document.createElement("div");
const viewFeed = `<section class="containerForm">
<div class="textUser">
<img src="./images/user.png" alt="imagenPerfil">
<h2> Usuario</h2>
<button id="logOutBtn" class="logOutBtn">Cerrar Cesión</button>
</div>
</section>
<section class="containerForm">
<form id="postform" class="postform">
<label for="postTitle" class="containerForm">
<input type="text" name="postTitle" id="postTitle" class="postTitle" placeholder="Tips">
</label>
<label for="postText" class="containerForm">
<textarea type="text" name="postText" id="postText" class="postText" rows="5" placeholder="Comparte tus tips aquí..."></textarea>
</label>
<div class="containerForm">
<button id="postBtn" class="postBtn">Publicar</button>
</div>
</form>
</section>`;

divFeed.innerHTML = viewFeed;


const userOut = divFeed.querySelector('.logOutBtn');
userOut.addEventListener('click', (e) => {
e.preventDefault();
logOut();
window.location.href = '#/';
});


let statusPost = '';
let idPost ='';

//Formulario enviado a DOM
const postForm = divFeed.querySelector("#postform");
postForm.addEventListener("submit", (e) => {
e.preventDefault();
//llama al input y textarea
const title = divFeed.querySelector("#postTitle");
const postText = divFeed.querySelector("#postText");

console.log(title.value);

statusPost !== true ? savePost(title.value, postText.value) : updatePost(idPost, {title: title.value, text: postText.value});


//Resetea el formulario, lo limpia
postForm.reset();
});


//crea el post en tiempo real
const createPost = async () => {
onGetPost((snapShot) => {
let card = "";

const divPost = document.getElementById("rootPost");

//recorre el array de docs de firebase
snapShot.forEach((doc) => {
//console.log(doc.data())
const docData = doc.data(); //el .data() convierte los objetos firebase a obj JS

card += `<div class="containerForm">
<div class="titlePost">

<h3>${docData.title}</h3>
</div>
<div class="textPost">
<p>${docData.text}</p>
</div>
<div>
<button class="btnEdit" data-id="${doc.id}">Editar</button>
<button class="btnDelete" data-id="${doc.id}">Eliminar</button>
</div>
</div>`;
});

divPost.innerHTML = card;

const btnsDelete = divPost.querySelectorAll(".btnDelete");
btnsDelete.forEach((btn) => {
btn.addEventListener("click", (event) => {
deletePost(event.target.dataset.id);
});
});

const btnsEdit = divPost.querySelectorAll(".btnEdit");
btnsEdit.forEach((btn) => {
btn.addEventListener("click", async (event) => {
const doc = await editPost(event.target.dataset.id);

const docData = doc.data();

const title = divFeed.querySelector("#postTitle");
const postText = divFeed.querySelector("#postText");

title.value = docData.title;
postText.value = docData.text;

statusPost = true;
idPost = doc.id;



});
});
});
};

//console.log(createPost());
createPost();




return divFeed;
};
29 changes: 29 additions & 0 deletions src/lib/views/templateMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

//Función que contiene vista del Menu
export const menuLogin = () => {
const divMenuLogin = document.createElement("div");
const viewMenuLogin = `<div class="containerIndex">
<div class="tips">
<img src="images/deformitoTip.png" width="200px" height="200px">
Tips Adulto Independiente
</div>
<div class="comunity">
Únete a la comunidad y
conoce todos los secretos
para vivir sol@ antes de los 30
</div>
<button class="logIn">
Inicia sesión con google
</button>
<section class="signUp">
<p>
¿No tienes cuenta aún? Regístrate <a href= 3\SCL020-social-network\src\images\error.jpg>aquí.</a>
</p>
<img src="images/deformitoTierno.png" width="160px" height="160px"></section>
</div>`
divMenuLogin.innerHTML = viewMenuLogin;
return divMenuLogin;


};

Loading