git ssb

3+

arj / patchbook



Tree: 2573a179d5ad71c5d17bc1c69426abedc216e8c4

Files: 2573a179d5ad71c5d17bc1c69426abedc216e8c4 / message / html / render / about-subjective.js

1710 bytesRaw
1const { h, Value, computed } = require('mutant')
2var nest = require('depnest')
3var extend = require('xtend')
4
5exports.needs = nest({
6 'about.obs.latestValue': 'first',
7 'sbot.async.get': 'first',
8 'book.html.simpleEmoji': 'first',
9 'message.html': {
10 decorate: 'reduce',
11 layout: 'first',
12 markdown: 'first'
13 }
14})
15
16exports.gives = nest('message.html.render')
17
18exports.create = function (api) {
19 return nest('message.html.render', subjective)
20
21 function subjective(msg, opts) {
22 if (!msg.value || !msg.value.content)
23 return
24
25 const content = msg.value.content
26
27 if (content.type == 'about' && content.rating && content.ratingType)
28 {
29 const element = api.message.html.layout(msg, extend({
30 content: renderSubjective(msg),
31 layout: content.review ? 'default' : 'mini'
32 }, opts))
33
34 return api.message.html.decorate(element, { msg })
35 }
36 }
37
38 function bookTitle(msg) {
39 const name = Value('')
40 const bookKey = msg.value.content.about
41 api.sbot.async.get(bookKey, (err, msg) => {
42 let originalTitle = msg.content.title
43 let latestTitle = api.about.obs.latestValue(bookKey, 'title')()
44 name.set(latestTitle || originalTitle)
45 })
46 return name
47 }
48
49 function renderSubjective(msg) {
50 let title = bookTitle(msg)
51 const content = msg.value.content
52 return ['Rated ', h('a', { href: msg.value.content.about }, title),
53 ' ' + content.rating + ' ',
54 h('span.text', { innerHTML:
55 computed(content.ratingType,
56 api.book.html.simpleEmoji) }),
57 computed(content.review, api.message.html.markdown)
58 ]
59 }
60}
61

Built with git-ssb-web