From 1e455720e8e0004c6e414644af20c7ef05ef380e Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Wed, 21 Apr 2021 21:42:26 -0600 Subject: [PATCH] Add "Reading" shelf to loggedIn home page --- app/views/home/controller.js | 1 + app/views/home/loggedIn.js | 36 +++++++++++++++++++++++++++++++++ app/views/shelves/controller.js | 10 ++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/app/views/home/controller.js b/app/views/home/controller.js index 7b55248..46e2a29 100644 --- a/app/views/home/controller.js +++ b/app/views/home/controller.js @@ -10,6 +10,7 @@ class HomeController extends ViewController { recentUpdates: [], }, loggedIn: { + readingShelfId: null, updates: [], // statuses, ratings, and reviews from people you follow. interactions: [], // likes, comments, recommendations, etc. }, diff --git a/app/views/home/loggedIn.js b/app/views/home/loggedIn.js index a383161..bfaba86 100644 --- a/app/views/home/loggedIn.js +++ b/app/views/home/loggedIn.js @@ -1,11 +1,47 @@ const html = require('choo/html'); +const { ShelvesController } = require('../shelves/controller'); + const loggedInView = (homeController, emit) => { const { __ } = homeController.i18n; + const shelvesController = new ShelvesController(homeController.appState, homeController.appState.i18n); + + const { readingShelfId } = homeController.state; + const readingShelf = readingShelfId && typeof shelvesController.state.loadedShelves[readingShelfId] !== 'undefined' + ? shelvesController.state.loadedShelves[readingShelfId] + : null; + console.log(readingShelf); + + if (shelvesController.appState.isFrontend && shelvesController.state.myShelves.length <= 0) { + shelvesController.getUserShelves().then(() => { + const readingShelfId = shelvesController.state.myShelves.find(shelf => shelf.name === 'Reading').id; + console.log(readingShelfId); + homeController.state.readingShelfId = readingShelfId + '/'; + console.log(homeController.state); + return shelvesController.getShelf(homeController.state.readingShelfId); + }).then(() => { + emit(shelvesController.appState.events.RENDER); + }); + } + return [ html`

${__('home.logged_in.subtitle')}

+
+

Reading

+
+ ${ + readingShelf === null + ? html`` + : readingShelf.shelfItems.map((shelfItem, shelfItemIndex) => { + return html`
+ ${ shelfItem.title } +
`; + }) + } +
+
diff --git a/app/views/shelves/controller.js b/app/views/shelves/controller.js index 3a4a098..91ab35d 100644 --- a/app/views/shelves/controller.js +++ b/app/views/shelves/controller.js @@ -36,11 +36,15 @@ class ShelvesController extends ViewController { }); } + getShelf (target) { + return fetch('/api/shelf/get/' + target).then(response => response.json()).then(shelf => { + this.state.loadedShelves[target] = shelf; + }); + } + getTargetShelf () { const target = this.targetShelf + '/' + (this.targetDomain !== null ? `${this.targetDomain}` : ''); - return fetch('/api/shelf/get/' + target).then(response => response.json()).then(shelf => { - this.state.loadedShelves[this.targetShelf] = shelf; - }); + return this.getShelf(target); } }