git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 66eb3aded58d22467d641cb52da1353212e8219a

Files: 66eb3aded58d22467d641cb52da1353212e8219a / plugs / message / html / layout / default.js

1833 bytesRaw
1const { when, h } = require('mutant')
2var nest = require('depnest')
3
4exports.needs = nest({
5 'profile.html.person': 'first',
6 'message.html': {
7 link: 'first',
8 meta: 'map',
9 action: 'map',
10 timestamp: 'first'
11 },
12 'about.html.image': 'first'
13})
14
15exports.gives = nest('message.html.layout')
16
17exports.create = function (api) {
18 return nest('message.html.layout', layout)
19
20 function layout (msg, opts) {
21 if (!(opts.layout === undefined || opts.layout === 'default')) return
22
23 var classList = ['Message']
24 var replyInfo = null
25
26 if (msg.value.content.root) {
27 classList.push('-reply')
28 var branch = msg.value.content.branch
29 if (branch) {
30 if (!opts.previousId || (opts.previousId && last(branch) && opts.previousId !== last(branch))) {
31 replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))])
32 }
33 }
34 }
35
36 return h('div', {
37 classList
38 }, [
39 messageHeader(msg, replyInfo),
40 h('section', [opts.content]),
41 when(msg.key, h('footer', [
42 h('div.actions', [
43 api.message.html.action(msg)
44 ])
45 ]))
46 ])
47
48 // scoped
49
50 function messageHeader (msg, replyInfo) {
51 return h('header', [
52 h('div.main', [
53 h('a.avatar', {href: `${msg.value.author}`}, [
54 api.about.html.image(msg.value.author)
55 ]),
56 h('div.main', [
57 h('div.name', [
58 api.profile.html.person(msg.value.author)
59 ]),
60 h('div.meta', [
61 api.message.html.timestamp(msg), ' ', replyInfo
62 ])
63 ])
64 ]),
65 h('div.meta', api.message.html.meta(msg))
66 ])
67 }
68 }
69}
70
71function last (array) {
72 if (Array.isArray(array)) {
73 return array[array.length - 1]
74 } else {
75 return array
76 }
77}
78

Built with git-ssb-web