git ssb

3+

arj / patchbook



Tree: b3369beb8b305b3fd5c63b483fdd8810799b0e2d

Files: b3369beb8b305b3fd5c63b483fdd8810799b0e2d / book / html / render.js

1235 bytesRaw
1const h = require('mutant/h')
2const Value = require('mutant/value')
3const when = require('mutant/when')
4const nest = require('depnest')
5
6exports.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
22exports.gives = nest({
23 'message.html': ['render'],
24 'book.html': ['render']
25})
26
27exports.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