Skip to content

Commit 4f63f15

Browse files
Merge pull request #1752 from ojanshu/impButton
Added a feature in Notes App to mark a note as important
2 parents c1d0aad + 83c4a8e commit 4f63f15

3 files changed

Lines changed: 59 additions & 7 deletions

File tree

Projects/Notes App/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
</nav>
2424
<div class="your-notes">
2525
Your Notes
26+
<ul id="notesContainer"></ul>
2627
</div>
2728
<div class="popup-box">
2829
<div class="popup">

Projects/Notes App/script.js

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const addBox = document.querySelector(".add-box"),
99

1010
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
1111

12+
const notesContainer = document.getElementById("notesContainer");
13+
1214
const notes = JSON.parse(localStorage.getItem("notes") || "[]");
1315
let isUpdate = false, updateId;
1416

@@ -26,9 +28,13 @@ closeIcon.addEventListener("click", () => {
2628
})
2729

2830
function showNote() {
31+
32+
notesContainer.innerHTML = "";
2933
document.querySelectorAll(".note").forEach(note =>note.remove());
3034
notes.forEach((note, index) => {
31-
liTag = `<li class="note">
35+
const liClass = note.isImportant ? "note starred" : "note";
36+
37+
const liTag = `<li class="${liClass}" style="background-color: ${note.isImportant ? 'gold' : ''}; color:${note.isImportant ? 'black' : 'white'}">
3238
<div class="details">
3339
<p>${note.title}</p>
3440
<span>${note.description}</span>
@@ -40,13 +46,14 @@ function showNote() {
4046
<ul class="menu">
4147
<li onclick="updateNote(${index},'${note.title}','${note.description}')"> <i class="uil uil-pen"></i>Edit</li>
4248
<li onclick="deleteNote(${index})"> <i class="uil uil-trash"></i>Delete</li>
49+
<li onclick="importantNote(${index})"> <i class="uil uil-heart${note.isImportant ? '-break' : ''}"></i>${note.isImportant ? 'Unstar' : 'Star'}</li>
4350
</ul>
4451
</div>
4552
</div>
46-
</li>`
47-
addBox.insertAdjacentHTML("afterend", liTag);
53+
</li>`;
54+
addBox.insertAdjacentHTML("afterend", liTag);
4855
});
49-
}
56+
}
5057
showNote();
5158

5259
function showMenu(elem){
@@ -77,6 +84,38 @@ function updateNote(noteId,title,desc){
7784
console.log(noteId,title,desc);
7885
}
7986

87+
function importantNote(noteId) {
88+
notes[noteId].isImportant = !notes[noteId].isImportant;
89+
renderNotes();
90+
}
91+
92+
function renderNotes() {
93+
notesContainer.innerHTML = "";
94+
document.querySelectorAll(".note").forEach(note =>note.remove());
95+
notes.forEach((note, index) => {
96+
const liClass = note.isImportant ? "note starred" : "note";
97+
98+
const liTag = `<li class="${liClass}" style="background-color: ${note.isImportant ? 'gold' : ''};">
99+
<div class="details">
100+
<p>${note.title}</p>
101+
<span>${note.description}</span>
102+
</div>
103+
<div class="bottom-content">
104+
<span>${note.date}</span>
105+
<div class="settings">
106+
<i onclick="showMenu(this)" class="uil uil-ellipsis-h"></i>
107+
<ul class="menu">
108+
<li onclick="updateNote(${index},'${note.title}','${note.description}')"> <i class="uil uil-pen"></i>Edit</li>
109+
<li onclick="deleteNote(${index})"> <i class="uil uil-trash"></i>Delete</li>
110+
<li onclick="importantNote(${index})"> <i class="uil uil-heart${note.isImportant ? '-break' : ''}"></i>${note.isImportant ? 'Unstar' : 'Star'}</li>
111+
</ul>
112+
</div>
113+
</div>
114+
</li>`;
115+
addBox.insertAdjacentHTML("afterend", liTag);
116+
});
117+
}
118+
80119
for (var i = 0; i < addBtn.length; i++) {
81120
addBtn[i].addEventListener("click", e => {
82121
e.preventDefault();
@@ -124,4 +163,7 @@ function updateNote(noteId,title,desc){
124163
//console.log(cardTxt);
125164

126165
})
127-
})
166+
})
167+
168+
showNote();
169+
renderNotes();

Projects/Notes App/style.css

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ header img{
160160
.menu li i{
161161
padding-right: 10px;
162162
}
163-
.popup-box{
163+
.popup-box {
164164
position: fixed;
165165
top: 0;
166166
left: 0;
@@ -318,4 +318,13 @@ form .row label{
318318
header img{
319319
margin-right:4px;
320320
}
321-
}
321+
}
322+
323+
.starred{
324+
background-color: gold;
325+
}
326+
327+
.note.starred * {
328+
color: black;
329+
}
330+

0 commit comments

Comments
 (0)