import html from 'choo/html'; import { SearchController } from './controller'; // The controller for this view, where processing should happen. import { resultDetails } from './resultDetails'; // This is the view function that is exported and used in the view manager. export const searchView = (state, emit, i18n) => { const controller = new SearchController(state, i18n); const { __ } = controller.i18n; if (controller.state.lastSearch !== state.query.for) { 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`

${__('search.header')}

${controller.doneSearching ? html`${__('search.results_header')} ${controller.state.lastSearch}` : html` ${__('search.loading')}` }

${!controller.doneSearching || controller.results.works < 1 ? [ html`

${__('search.no_results')}

`, html` ${__('search.no_results_suggestion')} ` ] : controller.results.works.map(result => { return html`

${result.name}

${result.description ? html`

${result.description}

` : null}
${resultDetails(controller, result, emit)}
`; }) }
`, ]; }