check for null case booklist

pull/1/head
Adam Undus 2020-10-08 14:59:05 -04:00
parent f935630711
commit 45a809bcc1
1 changed files with 3 additions and 2 deletions

View File

@ -3,7 +3,8 @@
const url = window.location && window.location.toString().split('/'); const url = window.location && window.location.toString().split('/');
const bookId = url[url.length - 1].match(/(\d+)/)[0]; const bookId = url[url.length - 1].match(/(\d+)/)[0];
if (JSON.parse(localStorage.getItem('booklist'))[bookId]) { const currentList = JSON.parse(localStorage.getItem('booklist'));
if (currentList && currentList[bookId]) {
// book already in list // book already in list
addbtn.html('Remove book from My Book List') addbtn.html('Remove book from My Book List')
addbtn.css("background-color", "indianred"); addbtn.css("background-color", "indianred");
@ -31,7 +32,7 @@
bookId: bookId, bookId: bookId,
imgSrc: $('img.cover-art').attr('src'), imgSrc: $('img.cover-art').attr('src'),
author: author, author: author,
url: window.location url: window.location.href
}; };
const newList = { ...JSON.parse(localStorage.getItem('booklist')) }; const newList = { ...JSON.parse(localStorage.getItem('booklist')) };