Files: 4d9f238ff73f7136cd292da88f06c17fe1a8c445 / lib / depject / message / html / render / made-changes.js
1224 bytesRaw
1 | const h = require('mutant/h') |
2 | const nest = require('depnest') |
3 | const extend = require('xtend') |
4 | const ref = require('ssb-ref') |
5 | const addContextMenu = require('../../../../message/html/decorate/context-menu') |
6 | |
7 | exports.needs = nest({ |
8 | 'message.html': { |
9 | layout: 'first' |
10 | }, |
11 | 'about.obs.latestValue': 'first', |
12 | 'intl.sync.i18n': 'first' |
13 | }) |
14 | |
15 | exports.gives = nest('message.html', { |
16 | canRender: true, |
17 | render: true |
18 | }) |
19 | |
20 | exports.create = function (api) { |
21 | const i18n = api.intl.sync.i18n |
22 | return nest('message.html', { |
23 | canRender: isRenderable, |
24 | render: function about (msg, opts) { |
25 | if (!isRenderable(msg)) return |
26 | |
27 | const action = i18n('made changes to') |
28 | const target = msg.value.content.about |
29 | const title = api.about.obs.latestValue(target, 'title') |
30 | const element = api.message.html.layout(msg, extend({ |
31 | showActions: true, |
32 | miniContent: [action, ' ', h('a', { |
33 | href: target |
34 | }, title)], |
35 | layout: 'mini' |
36 | }, opts)) |
37 | |
38 | return addContextMenu(element, { |
39 | msg |
40 | }) |
41 | } |
42 | }) |
43 | |
44 | function isRenderable (msg) { |
45 | if (msg.value.content.type !== 'about') return |
46 | if (!ref.isMsg(msg.value.content.about)) return |
47 | return true |
48 | } |
49 | } |
50 |
Built with git-ssb-web