2020-09-21 01:19:12 +02:00
|
|
|
const html = require('choo/html');
|
2019-10-18 04:56:57 +02:00
|
|
|
|
2021-04-22 05:42:26 +02:00
|
|
|
const { ShelvesController } = require('../shelves/controller');
|
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
const loggedInView = (homeController, emit) => {
|
2019-10-18 04:56:57 +02:00
|
|
|
const { __ } = homeController.i18n;
|
|
|
|
|
2021-04-22 05:42:26 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-18 04:56:57 +02:00
|
|
|
return [
|
|
|
|
html`<section>
|
2019-12-01 22:08:12 +01:00
|
|
|
<h2>${__('home.logged_in.subtitle')}</h2>
|
2021-04-22 05:42:26 +02:00
|
|
|
<div class="card">
|
|
|
|
<header><h3>Reading</h3></header>
|
|
|
|
<footer>
|
|
|
|
${
|
|
|
|
readingShelf === null
|
|
|
|
? html`<i class="icon-loading animate-spin"></i>`
|
|
|
|
: readingShelf.shelfItems.map((shelfItem, shelfItemIndex) => {
|
|
|
|
return html`<div>
|
|
|
|
${ shelfItem.title }
|
|
|
|
</div>`;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</footer>
|
|
|
|
</div>
|
2019-10-18 04:56:57 +02:00
|
|
|
<div class="flex one two-700">
|
|
|
|
<div>
|
|
|
|
<div class="card">
|
|
|
|
<header>
|
2019-12-01 22:08:12 +01:00
|
|
|
<h3>${__('home.logged_in.updates')}</h3>
|
2019-10-18 04:56:57 +02:00
|
|
|
<button class="small pseudo pull-right tooltip-left" data-tooltip=${__('interaction.reload')}>
|
|
|
|
<i class="icon-reload"></i>
|
|
|
|
</button>
|
|
|
|
</header>
|
|
|
|
<footer>
|
|
|
|
${homeController.state.loggedIn.updates.map(update => reviewCard(homeController, update))}
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div class="card">
|
|
|
|
<header>
|
2019-12-01 22:08:12 +01:00
|
|
|
<h3>${__('home.logged_in.interactions')}</h3>
|
2019-10-18 04:56:57 +02:00
|
|
|
<button class="small pseudo pull-right tooltip-left" data-tooltip=${__('interaction.reload')}>
|
|
|
|
<i class="icon-reload"></i>
|
|
|
|
</button>
|
|
|
|
</header>
|
|
|
|
<footer>
|
|
|
|
${homeController.state.loggedIn.interactions.map(interaction => reviewCard(homeController, interaction))}
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>`,
|
|
|
|
];
|
2020-09-21 01:19:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { loggedInView };
|