import html from 'choo/html'; import { starRating } from '../partials/starRating'; import { modal } from '../partials/modal'; export const shelfView = (shelvesController, emit) => { const { __ } = shelvesController.i18n; if (shelvesController.targetShelf === null) { return [ html`

${__('shelves.no_shelf_selected')}

${__('shelves.not_logged_in')}

`, ]; } if (typeof shelvesController.state.loadedShelves[shelvesController.targetShelf] === 'undefined') { shelvesController.getTargetShelf().then(() => { emit('render'); }); } const shelf = typeof shelvesController.state.loadedShelves[shelvesController.targetShelf] !== 'undefined' ? shelvesController.state.loadedShelves[shelvesController.targetShelf] : null; if (shelf === null) { return [ html`

${__('shelves.loading')}

`, ]; } if (typeof shelf.error !== 'undefined') { return [ html`

${__('global.error')}

${shelf.message}
`, ]; } const shelfItems = shelf !== null ? shelf.shelfItems : []; // 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`

${shelf.name}

${__('shelves.owned_by')} ${shelf.user === null ? __('shelves.you') : `${shelf.user.name}`}
${shelfItems.map((shelfItem, index) => { return html`
`; })}
`, ]; }