git ssb

10+

Matt McKegg / patchwork



Tree: e1c938e079d739f9e8511262531b1d04e30effab

Files: e1c938e079d739f9e8511262531b1d04e30effab / overrides / patchcore / message / html / action / reply.js

977 bytesRaw
1var h = require('mutant/h')
2var nest = require('depnest')
3
4exports.needs = nest({
5 'intl.sync.i18n': 'first',
6 'app.navigate': 'first',
7 'message.sync.root': 'first'
8
9})
10
11exports.gives = nest('message.html.action')
12
13exports.create = (api) => {
14 const i18n = api.intl.sync.i18n
15 return nest('message.html.action', function reply (msg) {
16 return h('a', { href: msg.key, anchor: 'reply', 'ev-click': {handleEvent, api, msg} }, i18n('Reply'))
17 })
18}
19
20function handleEvent (ev) {
21 var {api, msg} = this
22 var el = getMessageElement(ev.target)
23
24 // HACK: if this is the last message in the list, reply to the root message
25 if (el && !el.nextElementSibling) {
26 api.app.navigate(api.message.sync.root(msg), 'reply')
27 ev.preventDefault()
28 }
29}
30
31function getMessageElement (el) {
32 while (el && el.classList) {
33 if (el.classList.contains('Message') && el.parentNode && el.parentNode.classList.contains('replies')) {
34 return el
35 }
36 el = el.parentNode
37 }
38}
39

Built with git-ssb-web