Files: d6861e3a6c97728f151fbc42d87fe7b565358976 / bookmark / html / render.js
1783 bytesRaw
1 | const { h, Value, when, computed } = require('mutant') |
2 | const nest = require('depnest') |
3 | |
4 | exports.needs = nest({ |
5 | 'blob.sync.url': 'first', |
6 | 'bookmark.obs.bookmark': 'first', |
7 | 'feed.html.render': 'first', |
8 | 'keys.sync.load': 'first', |
9 | 'about.html.link': 'first', |
10 | 'about.html.image': 'first', |
11 | 'message.html': { |
12 | decorate: 'reduce', |
13 | link: 'first', |
14 | markdown: 'first', |
15 | backlinks: 'first', |
16 | meta: 'map', |
17 | action: 'map', |
18 | timestamp: 'first', |
19 | }, |
20 | }) |
21 | |
22 | exports.gives = nest({ |
23 | 'message.html': [ 'render' ], |
24 | 'bookmark.html': [ 'render' ] |
25 | }) |
26 | |
27 | exports.create = function(api) { |
28 | const { timestamp, meta, backlinks, action } = api.message.html |
29 | |
30 | return nest({ |
31 | 'message.html.render': renderBookmark, |
32 | 'bookmark.html.render': renderBookmark |
33 | }) |
34 | |
35 | function renderBookmark(msg, { pageId } = {}) { |
36 | if (!msg.value || (msg.value.content.type !== 'bookmark')) return |
37 | |
38 | const bookmark = api.bookmark.obs.bookmark(msg.key) |
39 | |
40 | const content = [ |
41 | h('a', { href: bookmark.messageId }, [ |
42 | h('.details', [ |
43 | h('Title', bookmark.title), |
44 | h('Description', bookmark.description), |
45 | h('Tags', bookmark.tags().map(tag => |
46 | h('Tag', tag) |
47 | )) |
48 | ]) |
49 | ]) |
50 | ] |
51 | |
52 | const message = h( |
53 | 'Message -bookmark', |
54 | [ |
55 | h('section.avatar', {}, api.about.html.image(msg.value.author)), |
56 | h('section.timestamp', {}, timestamp(msg)), |
57 | h('section.meta', {}, meta(msg)), |
58 | h('section.content', {}, content), |
59 | h('section.actions', {}, action(msg)), |
60 | h('footer.backlinks', {}, backlinks(msg)) |
61 | ] |
62 | ) |
63 | |
64 | const element = h( |
65 | 'div', |
66 | { attributes: { tabindex: '0' } }, |
67 | message |
68 | ) |
69 | |
70 | return api.message.html.decorate(element, { msg }) |
71 | } |
72 | } |
73 |
Built with git-ssb-web