Show shelves when clicking add from search
This commit is contained in:
parent
080e194e27
commit
1509cf9d43
|
@ -1,4 +1,5 @@
|
||||||
import { ViewController } from '../controller';
|
import { ViewController } from '../controller';
|
||||||
|
import { ShelvesController } from '../shelves/controller';
|
||||||
|
|
||||||
export class SearchController extends ViewController {
|
export class SearchController extends ViewController {
|
||||||
constructor(state, emit, i18n) {
|
constructor(state, emit, i18n) {
|
||||||
|
@ -13,6 +14,7 @@ export class SearchController extends ViewController {
|
||||||
done: true,
|
done: true,
|
||||||
results: [],
|
results: [],
|
||||||
openModal: null,
|
openModal: null,
|
||||||
|
showShelves: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.emit = emit;
|
this.emit = emit;
|
||||||
|
@ -44,6 +46,19 @@ export class SearchController extends ViewController {
|
||||||
return this.state.openModal;
|
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) {
|
set openModal(modalId) {
|
||||||
this.state.openModal = modalId;
|
this.state.openModal = modalId;
|
||||||
}
|
}
|
||||||
|
@ -85,4 +100,16 @@ export class SearchController extends ViewController {
|
||||||
|
|
||||||
return Promise.resolve();
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -86,10 +86,13 @@ export const resultDetails = (searchController, result, emit = () => {}) => {
|
||||||
</div>
|
</div>
|
||||||
<div class="sixth-700">
|
<div class="sixth-700">
|
||||||
<p>
|
<p>
|
||||||
<button class="success">
|
<button class="success" onclick=${() => searchController.showShelves()}>
|
||||||
<i class="icon-plus"></i> <span>${__('interaction.add')}</span>
|
<i class="icon-plus"></i> <span>${__('interaction.add')}</span>
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
|
${!searchController.showShelves ? null : html`<ul>${searchController.shelves.map(shelf => {
|
||||||
|
return html`<li><a href="javascript:void(0)">${shelf.name}</a></li>`;
|
||||||
|
})}</ul>`}
|
||||||
<p>
|
<p>
|
||||||
<a class="small button" href=${result.link} target="_blank">
|
<a class="small button" href=${result.link} target="_blank">
|
||||||
${__('search.see_book_details')}
|
${__('search.see_book_details')}
|
||||||
|
|
Loading…
Reference in New Issue