MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / favoriteNote

Function favoriteNote

assets/js/note-app.js:249–271  ·  view source on GitHub ↗
(index)

Source from the content-addressed store, hash-verified

247
248//this function will change the favorite state of the note
249function favoriteNote(index){
250
251 let notes = localStorage.getItem('notes');
252 let notesObj;
253
254 if(notes == null){
255 notesObj = [];
256 }
257 else{
258 notesObj = JSON.parse(notes);
259 }
260
261 //we set the new favorite state
262 notesObj[index].favorite = !notesObj[index].favorite;
263 //Finally, we save it into the localstorage
264 localStorage.setItem('notes', JSON.stringify(notesObj));
265
266 showNotes();
267
268 //We check if the user was already watching only the favorites
269 if(showing_favs) showFavorites();
270
271}
272
273/*
274further features

Callers

nothing calls this directly

Calls 3

stringifyMethod · 0.80
showNotesFunction · 0.70
showFavoritesFunction · 0.70

Tested by

no test coverage detected