From 1509cf9d432836e7648c2634889a9f08ca4f9409 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Mon, 15 Jun 2020 23:33:12 -0600 Subject: [PATCH] Show shelves when clicking add from search --- app/views/search/controller.js | 27 +++++++++++++++++++++++++++ app/views/search/resultDetails.js | 5 ++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/views/search/controller.js b/app/views/search/controller.js index 247f040..ce5d222 100644 --- a/app/views/search/controller.js +++ b/app/views/search/controller.js @@ -1,4 +1,5 @@ import { ViewController } from '../controller'; +import { ShelvesController } from '../shelves/controller'; export class SearchController extends ViewController { constructor(state, emit, i18n) { @@ -13,6 +14,7 @@ export class SearchController extends ViewController { done: true, results: [], openModal: null, + showShelves: false, }); this.emit = emit; @@ -44,6 +46,19 @@ export class SearchController extends ViewController { return this.state.openModal; } + get hasFetchedShelves() { + return typeof this.appState.viewStates.shelves !== 'undefined' + && typeof this.appState.viewStates.shelves.myShelves !== 'undefined' + && this.appState.viewStates.shelves.myShelves.length > 0; + } + + get shelves() { + if (this.hasFetchedShelves) { + return this.appState.viewStates.shelves.myShelves; + } + return []; + } + set openModal(modalId) { this.state.openModal = modalId; } @@ -85,4 +100,16 @@ export class SearchController extends ViewController { return Promise.resolve(); } + + async showShelves () { + const shelfController = new ShelvesController(this.appState, this.i18n); + if (!this.hasFetchedShelves) { + console.log('getting'); + await shelfController.getUserShelves(); + console.log('got'); + } + console.log(shelfController.myShelves); + this.showShelves = true; + this.emit('render'); + } } \ No newline at end of file diff --git a/app/views/search/resultDetails.js b/app/views/search/resultDetails.js index 89d17f1..8a3b208 100644 --- a/app/views/search/resultDetails.js +++ b/app/views/search/resultDetails.js @@ -86,10 +86,13 @@ export const resultDetails = (searchController, result, emit = () => {}) => {

-

+ ${!searchController.showShelves ? null : html``}

${__('search.see_book_details')}