const html = require('choo/html'); const { starRating } = require('../partials/starRating'); const { modal } = require('../partials/modal'); 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(shelvesController.appState.events.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') : html`${shelf.user.name}`} { delete shelvesController.state.loadedShelves[shelvesController.targetShelf]; emit(shelvesController.appState.events.RENDER); }}> Reload ${shelfItems.map((shelfItem, index) => { return html` `; })} `, ]; } module.exports = { shelfView };
${__('shelves.not_logged_in')}