This file contains hidden or 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
| /** | |
| * Takes in a doc ref and displays a note by reading its title, | |
| * body and timestap in the viewport | |
| * @param {object} doc firestore document reference | |
| */ | |
| const drawNote = (doc) => { | |
| let title, body, timestamp, id, data, hr, h2, h6, p, aDelete, aEdit; |
This file contains hidden or 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
| noteViewButton.addEventListener('click', () => { | |
| statusSpan.innerText = 'getting docs from Firestore...'; | |
| // hide the fields | |
| inputDiv.style.display = 'none'; | |
| let p; | |
| notesRef.get() |
This file contains hidden or 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
| /** | |
| * Writes the note to the firestore database creating a document | |
| * inside the 'notes' collection | |
| * @param {object} note object containing the note title, body and the event timestamp | |
| */ | |
| const saveNote = (note) => { | |
| notesRef.doc().set(note) | |
| .then(()=> { | |
| // updates the status after the note is created in the firestore | |
| statusSpan.innerText = 'note created'; |
This file contains hidden or 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
| // execution starts here when user clicks the 'save' button | |
| noteSaveButton.addEventListener('click', (evt) => { | |
| statusSpan.innerText='working...'; | |
| // get values from text fields | |
| consttitle = noteTitleInput.value.trim(); | |
| constbody = noteBodyTexArea.value.trim(); | |
| // won't store notes without a title |
This file contains hidden or 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
| // reference to an instance of Firebase Firestore | |
| const db = firebase.firestore(); | |
| // a reference to the notes collection inside the default firestore database | |
| // this is the collection where each note will be stored as a unique document | |
| const notesRef = db.collection('notes'); |
This file contains hidden or 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
| const config = { | |
| apiKey: "", | |
| authDomain: "", | |
| databaseURL: "", | |
| projectId: "", | |
| storageBucket: "", | |
| messagingSenderId: "", | |
| }; | |
| firebase.initializeApp(config); |
This file contains hidden or 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
| <!-- firebase imports --> | |
| <script src="https://www.gstatic.com/firebasejs/4.10.0/firebase.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/4.10.0/firebase-firestore.js"></script> | |
| <!-- Firebase init --> | |
| <script src="./js/firebase/__init.js"></script> | |
| <script src="./js/firebase/crud.js"></script> | |
| <!-- custom js --> | |
| <script src="./js/main.js"></script> |
This file contains hidden or 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
| <div id="view-notes-div"> | |
| <button id="note-view-button" class="button button-outline" type="submit">VIEW NOTES</button> | |
| <div id="display-notes-div"> | |
| <hr> | |
| </div> | |
| </div> |
This file contains hidden or 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
| <div id="inputs-div"> | |
| <form> | |
| <fieldset> | |
| <input id="note-title-input" type="text" placeholder="note title" maxlength="100" required autofocus> | |
| <textarea rows="8" id="note-body-textarea" type="text" placeholder="note body" required></textarea> | |
| </fieldset> | |
| <button id="note-save-button" class="button button-outline" type="submit">SAVE</button> | |
| </form> | |
| </div> |
This file contains hidden or 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
| <div id="header-div"> | |
| <h1> | |
| <a href="/">FIRESTORE NOTES</a> | |
| </h1> | |
| <div id="add-notes-div"> | |
| <h4>Status: | |
| <span id="status-span">idle...</span> | |
| </h4> | |
| </div> | |
| </div> |
NewerOlder