diff --git a/app/views/shelves/controller.js b/app/views/shelves/controller.js index 2383cea..35078be 100644 --- a/app/views/shelves/controller.js +++ b/app/views/shelves/controller.js @@ -7,7 +7,25 @@ export class ShelvesController extends ViewController { super(state, i18n, 'shelves', { openModal: null, // state value for edit modals myShelves: [], // array of objects in sort order with name, id, and deletability. - loadedShelves: {}, // object key is shelf id with name and shelfItems + loadedShelves: { // object key is shelf id with name and shelfItems + 0: { + name: 'Test Shelf', + user: { + userName: 'testinTesterton', + displayName: 'Testin Testerton', + }, + shelfItems: [ + { + name: 'Book Title', + author: 'Someone Talented', + coverURL: 'https://picnicss.com/web/img/optimised.svg', + coverEdition: 'Special Edition', + rating: 4, + review: 'The Special Edition of Book Title by Someone Talented is my favorite thing in the whole world. I think and dream about it constantly and there is nothing better in the whole world.', + } + ] + }, + }, }); // If using controller methods in an input's onchange or onclick instance, @@ -31,4 +49,10 @@ export class ShelvesController extends ViewController { this.state.myShelves = shelves; }); } + + getTargetShelf () { + return fetch('/api/shelf/get/' + this.targetShelf).then(response => response.json()).then(shelf => { + this.state.loadedShelves[this.targetShelf] = shelf; + }); + } } \ No newline at end of file diff --git a/app/views/shelves/shelf.js b/app/views/shelves/shelf.js index 579ba3e..4ee1be4 100644 --- a/app/views/shelves/shelf.js +++ b/app/views/shelves/shelf.js @@ -1,11 +1,94 @@ import html from 'choo/html'; -export const shelfView = (homeController, emit) => { - const { __ } = homeController.i18n; +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')}

+
+
+ +
+
+
`, + ]; + } + + 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`
-

To Do

+
+
+

${shelf.name}

+ ${__('shelves.owned_by')} ${shelf.user.displayName} +
+
+ +
+
+ ${shelfItems.map((shelfItem, index) => { + return html`
+ +
`; + })}
`, ]; } \ No newline at end of file