2019-09-07 21:54:44 +02:00
|
|
|
import html from 'choo/html';
|
|
|
|
|
2019-09-10 01:08:11 +02:00
|
|
|
import { I18n } from '../../i18n';
|
2019-09-07 21:54:44 +02:00
|
|
|
import { SearchController } from './controller'; // The controller for this view, where processing should happen.
|
|
|
|
|
|
|
|
// This is the view function that is exported and used in the view manager.
|
|
|
|
export const searchView = (state, emit) => {
|
2019-09-10 01:08:11 +02:00
|
|
|
const i18n = new I18n(state);
|
2019-09-07 21:54:44 +02:00
|
|
|
const controller = new SearchController(state);
|
|
|
|
|
2019-09-10 01:08:11 +02:00
|
|
|
// if (!controller.state.done && controller.hasQuery) {
|
|
|
|
// controller.searchOpenLibrary(state.query.for).then(() => {
|
|
|
|
// emit('render');
|
|
|
|
// });
|
|
|
|
// }
|
2019-09-07 21:54:44 +02:00
|
|
|
|
|
|
|
// Returning an array in a view allows non-shared parent HTML elements.
|
|
|
|
// This one doesn't have the problem right now, but it's good to remember.
|
|
|
|
return [
|
|
|
|
html`<section>
|
2019-09-10 01:08:11 +02:00
|
|
|
<h2 class="subtitle">${i18n.__('search.header')}</h2>
|
2019-09-07 21:54:44 +02:00
|
|
|
|
|
|
|
<article>
|
|
|
|
${controller.results.map(result => {
|
|
|
|
return html`<div class="card">
|
|
|
|
<header>
|
|
|
|
${result.covers.map(cover => {
|
|
|
|
return html`<img src=${cover} />`;
|
|
|
|
})}
|
|
|
|
<h1 class="title">${result.title}</h1>
|
|
|
|
${result.authors.map(author => {
|
|
|
|
return html`<h2 class="subtitle">${author}</h2>`;
|
|
|
|
})}
|
|
|
|
</header>
|
|
|
|
</div>`;
|
|
|
|
})}
|
|
|
|
</article>
|
|
|
|
</section>`,
|
|
|
|
];
|
|
|
|
}
|