@@ -9,6 +9,8 @@ const addBox = document.querySelector(".add-box"),
99
1010const months = [ "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" ] ;
1111
12+ const notesContainer = document . getElementById ( "notesContainer" ) ;
13+
1214const notes = JSON . parse ( localStorage . getItem ( "notes" ) || "[]" ) ;
1315let isUpdate = false , updateId ;
1416
@@ -26,9 +28,13 @@ closeIcon.addEventListener("click", () => {
2628} )
2729
2830function 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+ }
5057showNote ( ) ;
5158
5259function 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 ( ) ;
0 commit comments