import html from 'choo/html'; 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) => { const i18n = new I18n(state); const controller = new SearchController(state); if (controller.state.lastSearch !== state.query.for) { console.log('searching!'); controller.search().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`

${i18n.__('search.header')}

${controller.doneSearching ? null : html`

`} ${controller.results.works < 1 ? null : [ html`

${i18n.__('search.books_header')}

`, controller.results.works.map(result => { return html`

${result.name}

${result.description ? html`

${result.description}

` : null}
`; }), ]} ${controller.results.series.length < 1 ? null : [ html`

${i18n.__('search.series_header')}

`, controller.results.series.map(result => { return html`

${result.name}

${result.description ? html`

${result.description}

` : null}
`; }), ]} ${controller.results.humans.length < 1 ? null : [ html`

${i18n.__('search.people_header')}

`, controller.results.humans.map(result => { return html`
${result.image ? html`` : null}

${result.name}

${result.description ? html`

${result.description}

` : null}
`; }), ]}
`, ]; }