Skip to content

Commit

Permalink
Merge pull request #1145 from gautamjuyal/tools-fix
Browse files Browse the repository at this point in the history
Notes taking app fix (#1142)
  • Loading branch information
swapnilsparsh authored Jan 23, 2024
2 parents 23e651b + fcd4561 commit 5e10076
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions 53 - Notes Taking App/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const addNoteButton = notesContainer.querySelector(".add-note");

let delete_element = false;
getNotes().forEach(note => {
const noteElement = createNoteElement(note.id, note.content);
notesContainer.insertBefore(noteElement, addNoteButton);
createNote(note.id, note.content)
});

addNoteButton.addEventListener("click", () => addNote());
Expand All @@ -26,11 +25,11 @@ function createNoteElement(id, content) {
const element = document.createElement("div");
element.classList.add("note");
element.value = content;
element.textContent = "Empty Note";
element.textContent = content ? content : "Empty Note";
element.setAttribute("contenteditable", "true")

element.addEventListener("change", () => {
updateNote(id, element.value);
element.addEventListener("keydown", () => {
updateNote(id, element.textContent);
});
element.addEventListener('click', (e) => {
if (element.textContent == "Empty Note") {
Expand Down Expand Up @@ -82,22 +81,25 @@ function createTextDecorationButtons(id, element) {
})
return [boldBtn, underlineBtn, italicBtn];
}
function createNote(id, content){
let note_container = createContainer();
notesContainer.insertBefore(note_container, addNoteButton);
const noteElement = createNoteElement(id, content);
note_container.appendChild(noteElement);
const deleteButton = createDeleteButton(id, note_container);
note_container.appendChild(deleteButton);
const decorateTextButtons = createTextDecorationButtons(id, note_container);
decorateTextButtons.forEach(e => {
note_container.appendChild(e)
});
}
function addNote() {
const notes = getNotes();
const noteObj = {
id: Math.floor(Math.random() * 100000),
content: ""
};
let note_conatiner = createContainer();
notesContainer.insertBefore(note_conatiner, addNoteButton);
const noteElement = createNoteElement(noteObj.id, noteObj.content);
note_conatiner.appendChild(noteElement);
const deleteButton = createDeleteButton(noteObj.id, note_conatiner);
note_conatiner.appendChild(deleteButton);
const decorateTextButtons = createTextDecorationButtons(noteObj.id, note_conatiner);
decorateTextButtons.forEach(e => {
note_conatiner.appendChild(e)
});
createNote(noteObj.id, noteObj.content)

notes.push(noteObj);
saveNotes(notes);
Expand Down

0 comments on commit 5e10076

Please sign in to comment.