Commit 3738a10330418ba685af21142b05c622732f4eec
move backlinks stuff into message.html.backlinks and use for all layouts
Matt McKegg committed on 6/8/2017, 12:12:56 AMParent: 3111373d72c14d67653f9863dbf6db812181252b
Files changed
modules/message/html/backlinks.js | added |
modules/page/html/render/message.js | changed |
plugs/message/html/layout/default.js | changed |
plugs/message/html/layout/mini.js | changed |
modules/message/html/backlinks.js | ||
---|---|---|
@@ -1,0 +1,56 @@ | ||
1 | +var nest = require('depnest') | |
2 | +var { h, map, computed } = require('mutant') | |
3 | + | |
4 | +exports.needs = nest({ | |
5 | + 'message.obs': { | |
6 | + backlinks: 'first', | |
7 | + forks: 'first', | |
8 | + name: 'first', | |
9 | + author: 'first' | |
10 | + }, | |
11 | + 'profile.html.person': 'first' | |
12 | +}) | |
13 | + | |
14 | +exports.gives = nest('message.html.backlinks') | |
15 | + | |
16 | +exports.create = function (api) { | |
17 | + return nest('message.html.backlinks', function (msg, {includeReferences = true, includeForks = true} = {}) { | |
18 | + var references = includeReferences ? api.message.obs.backlinks(msg.key) : [] | |
19 | + var forks = (includeForks && msg.value.content.root) ? api.message.obs.forks(msg.key) : [] | |
20 | + return [ | |
21 | + map(forks, msgId => { | |
22 | + return h('a.backlink', { | |
23 | + href: msgId, | |
24 | + title: msgId | |
25 | + }, [ | |
26 | + h('strong', [ | |
27 | + authorLink(msgId), ' forked this discussion:' | |
28 | + ]), ' ', | |
29 | + api.message.obs.name(msgId) | |
30 | + ]) | |
31 | + }), | |
32 | + map(references, msgId => { | |
33 | + return h('a.backlink', { | |
34 | + href: msgId, | |
35 | + title: msgId | |
36 | + }, [ | |
37 | + h('strong', [ | |
38 | + authorLink(msgId), ' referenced this message:' | |
39 | + ]), ' ', | |
40 | + api.message.obs.name(msgId) | |
41 | + ]) | |
42 | + }) | |
43 | + ] | |
44 | + }) | |
45 | + | |
46 | + function authorLink (msgId) { | |
47 | + var author = api.message.obs.author(msgId) | |
48 | + return computed(author, author => { | |
49 | + if (author) { | |
50 | + return api.profile.html.person(author) | |
51 | + } else { | |
52 | + return 'Someone' | |
53 | + } | |
54 | + }) | |
55 | + } | |
56 | +} |
modules/page/html/render/message.js | ||
---|---|---|
@@ -59,9 +59,9 @@ | ||
59 | 59 | h('div.messages', [ |
60 | 60 | when(thread.branchId, h('a.full', {href: thread.rootId}, ['View full thread'])), |
61 | 61 | map(thread.messages, (msg) => { |
62 | 62 | return computed([msg, thread.previousKey(msg)], (msg, previousId) => { |
63 | - return api.message.html.render(msg, {pageId: id, previousId, backlinks: true}) | |
63 | + return api.message.html.render(msg, {pageId: id, previousId, includeReferences: true}) | |
64 | 64 | }) |
65 | 65 | }) |
66 | 66 | ]), |
67 | 67 | compose |
plugs/message/html/layout/default.js | ||
---|---|---|
@@ -11,9 +11,10 @@ | ||
11 | 11 | 'message.html': { |
12 | 12 | link: 'first', |
13 | 13 | meta: 'map', |
14 | 14 | action: 'map', |
15 | - timestamp: 'first' | |
15 | + timestamp: 'first', | |
16 | + backlinks: 'first' | |
16 | 17 | }, |
17 | 18 | 'about.html.image': 'first' |
18 | 19 | }) |
19 | 20 | |
@@ -21,41 +22,35 @@ | ||
21 | 22 | |
22 | 23 | exports.create = function (api) { |
23 | 24 | return nest('message.html.layout', layout) |
24 | 25 | |
25 | - function layout (msg, opts) { | |
26 | - if (!(opts.layout === undefined || opts.layout === 'default')) return | |
26 | + function layout (msg, {layout, previousId, priority, content, includeReferences}) { | |
27 | + if (!(layout === undefined || layout === 'default')) return | |
27 | 28 | |
28 | - var backlinks = opts.backlinks ? api.message.obs.backlinks(msg.key) : [] | |
29 | - var forks = msg.value.content.root ? api.message.obs.forks(msg.key) : [] | |
30 | - | |
31 | 29 | var classList = ['Message'] |
32 | 30 | var replyInfo = null |
33 | 31 | |
34 | 32 | if (msg.value.content.root) { |
35 | 33 | classList.push('-reply') |
36 | 34 | var branch = msg.value.content.branch |
37 | 35 | if (branch) { |
38 | - if (!opts.previousId || (opts.previousId && last(branch) && opts.previousId !== last(branch))) { | |
36 | + if (!previousId || (previousId && last(branch) && previousId !== last(branch))) { | |
39 | 37 | replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))]) |
40 | 38 | } |
41 | 39 | } |
42 | 40 | } else if (msg.value.content.project) { |
43 | 41 | replyInfo = h('span', ['on ', api.message.html.link(msg.value.content.project)]) |
44 | 42 | } |
45 | 43 | |
46 | - if (opts.priority === 2) { | |
44 | + if (priority === 2) { | |
47 | 45 | classList.push('-new') |
48 | 46 | } |
49 | 47 | |
50 | 48 | return h('div', { |
51 | 49 | classList |
52 | 50 | }, [ |
53 | - messageHeader(msg, { | |
54 | - replyInfo, | |
55 | - priority: opts.priority | |
56 | - }), | |
57 | - h('section', [opts.content]), | |
51 | + messageHeader(msg, { replyInfo, priority }), | |
52 | + h('section', [content]), | |
58 | 53 | computed(msg.key, (key) => { |
59 | 54 | if (ref.isMsg(key)) { |
60 | 55 | return h('footer', [ |
61 | 56 | h('div.actions', [ |
@@ -63,37 +58,16 @@ | ||
63 | 58 | ]) |
64 | 59 | ]) |
65 | 60 | } |
66 | 61 | }), |
67 | - map(forks, msgId => { | |
68 | - return h('a.backlink', { | |
69 | - href: msgId, | |
70 | - title: msgId | |
71 | - }, [ | |
72 | - h('strong', [ | |
73 | - authorLink(msgId), ' forked this discussion:' | |
74 | - ]), ' ', | |
75 | - api.message.obs.name(msgId) | |
76 | - ]) | |
77 | - }), | |
78 | - map(backlinks, msgId => { | |
79 | - return h('a.backlink', { | |
80 | - href: msgId, | |
81 | - title: msgId | |
82 | - }, [ | |
83 | - h('strong', [ | |
84 | - authorLink(msgId), ' referenced this message:' | |
85 | - ]), ' ', | |
86 | - api.message.obs.name(msgId) | |
87 | - ]) | |
88 | - }) | |
62 | + api.message.html.backlinks(msg, {includeReferences}) | |
89 | 63 | ]) |
90 | 64 | |
91 | 65 | // scoped |
92 | 66 | |
93 | 67 | function messageHeader (msg, {replyInfo, priority}) { |
94 | 68 | var additionalMeta = [] |
95 | - if (opts.priority >= 2) { | |
69 | + if (priority >= 2) { | |
96 | 70 | additionalMeta.push(h('span.flag -new', {title: 'New Message'})) |
97 | 71 | } |
98 | 72 | return h('header', [ |
99 | 73 | h('div.main', [ |
@@ -115,19 +89,8 @@ | ||
115 | 89 | additionalMeta |
116 | 90 | ]) |
117 | 91 | ]) |
118 | 92 | } |
119 | - | |
120 | - function authorLink (msgId) { | |
121 | - var author = api.message.obs.author(msgId) | |
122 | - return computed(author, author => { | |
123 | - if (author) { | |
124 | - return api.profile.html.person(author) | |
125 | - } else { | |
126 | - return 'Someone' | |
127 | - } | |
128 | - }) | |
129 | - } | |
130 | 93 | } |
131 | 94 | } |
132 | 95 | |
133 | 96 | function last (array) { |
plugs/message/html/layout/mini.js | ||
---|---|---|
@@ -9,9 +9,10 @@ | ||
9 | 9 | 'message.html': { |
10 | 10 | link: 'first', |
11 | 11 | meta: 'map', |
12 | 12 | action: 'map', |
13 | - timestamp: 'first' | |
13 | + timestamp: 'first', | |
14 | + backlinks: 'first' | |
14 | 15 | }, |
15 | 16 | 'about.html.image': 'first' |
16 | 17 | }) |
17 | 18 | |
@@ -19,40 +20,37 @@ | ||
19 | 20 | |
20 | 21 | exports.create = function (api) { |
21 | 22 | return nest('message.html.layout', layout) |
22 | 23 | |
23 | - function layout (msg, opts) { | |
24 | - if (!(opts.layout === 'mini')) return | |
24 | + function layout (msg, {layout, previousId, priority, miniContent, content, includeReferences}) { | |
25 | + if (!(layout === 'mini')) return | |
25 | 26 | |
26 | - var backlinks = opts.backlinks ? api.message.obs.backlinks(msg.key) : [] | |
27 | 27 | var classList = ['Message -mini'] |
28 | 28 | var replyInfo = null |
29 | 29 | |
30 | 30 | if (msg.value.content.root) { |
31 | 31 | classList.push('-reply') |
32 | 32 | var branch = msg.value.content.branch |
33 | 33 | if (branch) { |
34 | - if (!opts.previousId || (opts.previousId && last(branch) && opts.previousId !== last(branch))) { | |
34 | + if (!previousId || (previousId && last(branch) && previousId !== last(branch))) { | |
35 | 35 | replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))]) |
36 | 36 | } |
37 | 37 | } |
38 | 38 | } else if (msg.value.content.project) { |
39 | 39 | replyInfo = h('span', ['on ', api.message.html.link(msg.value.content.project)]) |
40 | 40 | } |
41 | 41 | |
42 | - if (opts.priority === 2) { | |
42 | + if (priority === 2) { | |
43 | 43 | classList.push('-new') |
44 | 44 | } |
45 | 45 | |
46 | 46 | return h('div', { |
47 | 47 | classList |
48 | 48 | }, [ |
49 | 49 | messageHeader(msg, { |
50 | - replyInfo, | |
51 | - priority: opts.priority, | |
52 | - miniContent: opts.miniContent | |
50 | + replyInfo, priority, miniContent | |
53 | 51 | }), |
54 | - h('section', [opts.content]), | |
52 | + h('section', [content]), | |
55 | 53 | computed(msg.key, (key) => { |
56 | 54 | if (ref.isMsg(key)) { |
57 | 55 | return h('footer', [ |
58 | 56 | h('div.actions', [ |
@@ -60,23 +58,16 @@ | ||
60 | 58 | ]) |
61 | 59 | ]) |
62 | 60 | } |
63 | 61 | }), |
64 | - map(backlinks, backlink => { | |
65 | - return h('a.backlink', { | |
66 | - href: backlink, | |
67 | - title: backlink | |
68 | - }, [ | |
69 | - h('strong', 'Referenced from'), ' ', api.message.obs.name(backlink) | |
70 | - ]) | |
71 | - }) | |
62 | + api.message.html.backlinks(msg, {includeReferences}) | |
72 | 63 | ]) |
73 | 64 | |
74 | 65 | // scoped |
75 | 66 | |
76 | 67 | function messageHeader (msg, {replyInfo, priority, miniContent}) { |
77 | 68 | var additionalMeta = [] |
78 | - if (opts.priority >= 2) { | |
69 | + if (priority >= 2) { | |
79 | 70 | additionalMeta.push(h('span.flag -new', {title: 'New Message'})) |
80 | 71 | } |
81 | 72 | return h('header', [ |
82 | 73 | h('div.main', [ |
Built with git-ssb-web