Refactor nav component so that it only displays books for which we have data

This commit is contained in:
Leonard Smith 2020-10-06 20:09:05 -05:00
parent b95c6510d4
commit 73400d8a66
1 changed files with 11 additions and 18 deletions

View File

@ -17,29 +17,22 @@ export default class ScriptureNavBarComponent extends Component {
constructor(...args) {
super(...args);
console.log(books);
this.books = this.availableBooks;
this.books = this.getBooks();
// console.log(this.books);
}
// get only the books that we have backend data for
get
availableBooks()
async getBooks()
{
return this.store.findAll('book').then(function(backendBooks) {
let available = [];
backendBooks.forEach(
value => {
let foundValue = books.find(function(book) {
return book['name'] == value.id
});
if(foundValue) {
available.push(foundValue);
}
});
return available;
}).then(function(response) {
console.log(response);
return response;
const results = await this.store.findAll('book');
this.books = results.map((book) => {
let foundValue = books.find(function(value) {
return value['name'] == book.id
});
if(foundValue) {
return foundValue;
}
});
}