Readlebee/app/views/search/index.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

import html from 'choo/html';
2019-09-10 01:08:11 +02:00
import { I18n } from '../../i18n';
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);
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');
// });
// }
// 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>
<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>`,
];
}