I have created a bookmark feature with the following functionality:
$scope.bookmarkPost = function(bookmark_post){
if(window.localStorage.bookmarks == null) {
user_bookmarks = [];
} else {
user_bookmarks = JSON.parse(window.localStorage.bookmarks)
}
var existing_post = find(user_bookmarks, function(post){ return post.title == bookmark_post.title; });
if(!existing_post){
user_bookmarks.push({
id: bookmark_post.pagid,
title : bookmark_post.title,
date: bookmark_post.created,
room: bookmark_post.room
});
}
console.log(JSON.stringify(user_bookmarks));
window.localStorage.bookmarks = JSON.stringify(user_bookmarks);
};
This implementation should add the post to an array of objects and store it in the local storage. I attempted to check for duplicate entries by comparing titles like this:
var existing_post = find(user_bookmarks, function(post){ return post.title == bookmark_post.title; });
To be transparent, I am uncertain about the exact purpose of this code snippet, but I haven't found any alternative solutions yet. Unfortunately, this check is not functioning properly, resulting in duplicate entries. Any suggestions on how to resolve this issue?