Files: c8ebe98ed356a8b95e516ca561f755e05ed43156 / book / html / render.js
1235 bytesRaw
1 | const h = require('mutant/h') |
2 | const Value = require('mutant/value') |
3 | const when = require('mutant/when') |
4 | const nest = require('depnest') |
5 | |
6 | exports.needs = nest({ |
7 | 'blob.sync.url': 'first', |
8 | 'book.obs.book': 'first', |
9 | 'book.html': { |
10 | 'layout': 'first' |
11 | }, |
12 | 'feed.html.render': 'first', |
13 | 'keys.sync.load': 'first', |
14 | 'about.html.link': 'first', |
15 | 'message.html': { |
16 | decorate: 'reduce', |
17 | link: 'first', |
18 | markdown: 'first' |
19 | } |
20 | }) |
21 | |
22 | exports.gives = nest({ |
23 | 'message.html': ['render'], |
24 | 'book.html': ['render'] |
25 | }) |
26 | |
27 | exports.create = function (api) { |
28 | return nest({ |
29 | 'message.html.render': renderBook, |
30 | 'book.html.render': renderBook |
31 | }) |
32 | |
33 | function renderBook (msg, { pageId } = {}) { |
34 | if (!msg.value || (msg.value.content.type !== 'bookclub')) return |
35 | |
36 | const isEditing = Value(false) |
37 | const isCard = Value(true) |
38 | |
39 | if (pageId === msg.key) isCard.set(false) |
40 | |
41 | const obs = api.book.obs.book(msg.key) |
42 | |
43 | const element = h('div', {attributes: {tabindex: '0'}}, |
44 | when(isCard, |
45 | api.book.html.layout(msg, {layout: 'card', isEditing, isCard, obs}), |
46 | api.book.html.layout(msg, {layout: 'detail', isEditing, isCard, obs}) |
47 | )) |
48 | |
49 | return api.message.html.decorate(element, { msg }) |
50 | } |
51 | } |
52 |
Built with git-ssb-web