2019-09-07 21:54:44 +02:00
|
|
|
import html from 'choo/html';
|
|
|
|
|
|
|
|
import { SearchController } from './controller'; // The controller for this view, where processing should happen.
|
2019-09-12 01:34:11 +02:00
|
|
|
import { resultDetails } from './resultDetails';
|
2019-09-07 21:54:44 +02:00
|
|
|
|
|
|
|
// This is the view function that is exported and used in the view manager.
|
2019-09-16 20:32:53 +02:00
|
|
|
export const searchView = (state, emit, i18n) => {
|
|
|
|
const controller = new SearchController(state, i18n);
|
|
|
|
const { __ } = controller.i18n;
|
2019-09-07 21:54:44 +02:00
|
|
|
|
2019-09-10 01:09:25 +02:00
|
|
|
if (controller.state.lastSearch !== state.query.for) {
|
|
|
|
controller.search().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-16 20:32:53 +02:00
|
|
|
<h1 class="title">${__('search.header')}</h1>
|
2019-09-07 21:54:44 +02:00
|
|
|
|
|
|
|
<article>
|
2019-09-11 01:36:49 +02:00
|
|
|
${controller.doneSearching ? null : html`<h2><i class="icon-loading animate-spin"></i></h2>`}
|
2019-09-11 01:16:01 +02:00
|
|
|
|
|
|
|
${controller.results.works < 1
|
|
|
|
? null
|
|
|
|
: [
|
2019-09-16 20:32:53 +02:00
|
|
|
html`<h2>${__('search.books_header')}</h2>`,
|
2019-09-11 01:16:01 +02:00
|
|
|
controller.results.works.map(result => {
|
|
|
|
return html`<div class="flex search-result">
|
2019-09-12 07:41:18 +02:00
|
|
|
<div class="two-third-800 half-500">
|
2019-09-11 01:16:01 +02:00
|
|
|
<h3 class="title">${result.name}</h3>
|
|
|
|
${result.description ? html`<h4 class="subtitle">${result.description}</h4>` : null}
|
2019-09-11 19:38:09 +02:00
|
|
|
</div>
|
2019-09-12 07:41:18 +02:00
|
|
|
<div class="third-800 half-500">
|
2019-09-13 01:04:50 +02:00
|
|
|
${resultDetails(controller, result, emit)}
|
2019-09-11 01:16:01 +02:00
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}),
|
|
|
|
]}
|
|
|
|
|
|
|
|
${controller.results.series.length < 1
|
|
|
|
? null
|
|
|
|
: [
|
2019-09-16 20:32:53 +02:00
|
|
|
html`<h2>${__('search.series_header')}</h2>`,
|
2019-09-11 01:16:01 +02:00
|
|
|
controller.results.series.map(result => {
|
|
|
|
return html`<div class="flex search-result">
|
2019-09-12 07:41:18 +02:00
|
|
|
<div class="two-third-800 half-500">
|
2019-09-11 01:16:01 +02:00
|
|
|
<h3 class="title">${result.name}</h3>
|
|
|
|
${result.description ? html`<h4 class="subtitle">${result.description}</h4>` : null}
|
|
|
|
</div>
|
2019-09-12 07:41:18 +02:00
|
|
|
<div class="third-800 half-500">
|
2019-09-16 20:32:53 +02:00
|
|
|
<span class="tooltip-left" data-tooltip=${__('search.see_details_tooltip')}>
|
2019-09-11 19:38:09 +02:00
|
|
|
<a class="small pseudo button" href=${result.link} target="_blank">
|
2019-09-16 20:32:53 +02:00
|
|
|
${__('search.see_inventaire_details')}
|
2019-09-11 19:38:09 +02:00
|
|
|
</a>
|
|
|
|
</span>
|
2019-09-11 01:16:01 +02:00
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}),
|
|
|
|
]}
|
|
|
|
|
|
|
|
${controller.results.humans.length < 1
|
|
|
|
? null
|
|
|
|
: [
|
2019-09-16 20:32:53 +02:00
|
|
|
html`<h2>${__('search.people_header')}</h2>`,
|
2019-09-11 01:16:01 +02:00
|
|
|
controller.results.humans.map(result => {
|
|
|
|
return html`<div class="flex search-result">
|
2019-09-12 07:41:18 +02:00
|
|
|
<div class="sixth">
|
2019-09-11 01:16:01 +02:00
|
|
|
${result.image ? html`<img src=${result.image.url} class="search-image">` : null}
|
|
|
|
</div>
|
2019-09-12 07:41:18 +02:00
|
|
|
<div class="half-800 two-third">
|
2019-09-11 01:16:01 +02:00
|
|
|
<h3 class="title">${result.name}</h3>
|
|
|
|
${result.description ? html`<h4 class="subtitle">${result.description}</h4>` : null}
|
|
|
|
</div>
|
2019-09-12 07:41:18 +02:00
|
|
|
<div class="third-800">
|
2019-09-16 20:32:53 +02:00
|
|
|
<span class="tooltip-left" data-tooltip=${__('search.see_details_tooltip')}>
|
2019-09-11 19:38:09 +02:00
|
|
|
<a class="small pseudo button" href=${result.link} target="_blank">
|
2019-09-16 20:32:53 +02:00
|
|
|
${__('search.see_inventaire_details')}
|
2019-09-11 19:38:09 +02:00
|
|
|
</a>
|
|
|
|
</span>
|
2019-09-11 01:16:01 +02:00
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}),
|
|
|
|
]}
|
2019-09-07 21:54:44 +02:00
|
|
|
</article>
|
|
|
|
</section>`,
|
|
|
|
];
|
|
|
|
}
|