From 73400d8a668c298dd05731b6fd5d1054753169a0 Mon Sep 17 00:00:00 2001 From: Leonard Smith Date: Tue, 6 Oct 2020 20:09:05 -0500 Subject: [PATCH] Refactor nav component so that it only displays books for which we have data --- app/components/scripture-nav-bar.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/app/components/scripture-nav-bar.js b/app/components/scripture-nav-bar.js index 5c78bdc..a148a18 100644 --- a/app/components/scripture-nav-bar.js +++ b/app/components/scripture-nav-bar.js @@ -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; + } }); }