Add: Experimental collections edit, book list, collection cover #151

This commit is contained in:
advplyr 2021-11-06 20:31:46 -05:00
parent 28ccd4e568
commit 465e6869c0
31 changed files with 555 additions and 60 deletions

View file

@ -40,7 +40,7 @@ class UserCollection {
var json = this.toJSON()
json.books = json.books.map(bookId => {
var _ab = audiobooks.find(ab => ab.id === bookId)
return _ab ? _ab.toJSON() : null
return _ab ? _ab.toJSONExpanded() : null
}).filter(b => !!b)
return json
}
@ -84,5 +84,24 @@ class UserCollection {
this.books = this.books.filter(bid => bid !== bookId)
this.lastUpdate = Date.now()
}
update(payload) {
let hasUpdates = false
for (const key in payload) {
if (key === 'books') {
if (payload.books && this.books.join(',') !== payload.books.join(',')) {
this.books = [...payload.books]
hasUpdates = true
}
} else if (this[key] !== undefined && this[key] !== payload[key]) {
hasUpdates = true
this[key] = payload[key]
}
}
if (hasUpdates) {
this.lastUpdate = Date.now()
}
return hasUpdates
}
}
module.exports = UserCollection