├── utils.js ├── auth.js ├── main.css ├── firestore.js ├── index.html └── app.js /utils.js: -------------------------------------------------------------------------------- 1 | // jshint esversion: 8 2 | export function getUUID() { 3 | var d = new Date().getTime(); 4 | var uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace( 5 | /[xy]/g, 6 | function (c) { 7 | var r = (d + Math.random() * 16) % 16 | 0; 8 | d = Math.floor(d / 16); 9 | return (c == "x" ? r : (r & 0x3) | 0x8).toString(16); 10 | } 11 | ); 12 | return uuid; 13 | } 14 | -------------------------------------------------------------------------------- /auth.js: -------------------------------------------------------------------------------- 1 | // jshint esversion: 8 2 | const auth = firebase.auth(); 3 | const provider = new firebase.auth.GoogleAuthProvider(); 4 | 5 | auth.languageCode = "es"; 6 | 7 | export async function login() { 8 | try { 9 | const response = await auth.signInWithPopup(provider); 10 | return response.user; 11 | } catch (error) { 12 | throw new Error(error); 13 | } 14 | } 15 | 16 | export function logout() { 17 | auth.signOut(); 18 | } 19 | -------------------------------------------------------------------------------- /main.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Arial, Helvetica, sans-serif; 3 | } 4 | 5 | #app { 6 | width: 700px; 7 | margin: 0 auto; 8 | } 9 | 10 | #user-info { 11 | text-align: center; 12 | } 13 | #user-info img { 14 | border-radius: 50%; 15 | display: block; 16 | width: 100px; 17 | margin: 0 auto; 18 | } 19 | #user-info span { 20 | display: block; 21 | padding: 10px 0; 22 | font-weight: bolder; 23 | font-size: 28px; 24 | } 25 | 26 | input[type="text"] { 27 | box-sizing: border-box; 28 | padding: 10px 5px; 29 | width: 100%; 30 | border-radius: 5px; 31 | } 32 | 33 | #todos-container li { 34 | list-style: none; 35 | padding: 15px 0; 36 | font-size: 20px; 37 | border-bottom: 1px solid #eee; 38 | } 39 | #todos-container li:hover { 40 | background-color: #eee; 41 | } 42 | 43 | .hidden { 44 | display: none; 45 | } 46 | -------------------------------------------------------------------------------- /firestore.js: -------------------------------------------------------------------------------- 1 | // jshint esversion: 8 2 | const db = firebase.firestore(); 3 | export async function insert(item) { 4 | try { 5 | const response = await db.collection("todos").add(todo); 6 | return response; 7 | } catch (error) { 8 | throw new Error(error); 9 | } 10 | } 11 | 12 | export async function getItems(uid) { 13 | try { 14 | let items = []; 15 | const response = await db 16 | .collection("todos") 17 | .where("userid", "==", uid) 18 | .get(); 19 | 20 | response.forEach(function (item) { 21 | items.push(item.data()); 22 | }); 23 | 24 | return items; 25 | } catch (error) { 26 | throw new Error(error); 27 | } 28 | } 29 | 30 | export async function update(id, completed) { 31 | try { 32 | let docId; 33 | const doc = await db.collection("todos").where("id", "==", id).get(); 34 | doc.forEach((i) => { 35 | docId = i.id; 36 | }); 37 | 38 | await db.collection("todos").doc(docId).update({ completed: completed }); 39 | } catch (error) { 40 | throw new Error(error); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 |