git ssb

10+

Matt McKegg / patchwork



Commit efead363d153b58ea67532a7044afee4c76bb99a

"reply" on last message replies to root message

fixes #743
Matt McKegg committed on 2/20/2018, 7:04:34 AM
Parent: 22ab3f74fc9451203cde54a3db310851b3ac6870

Files changed

lib/anchor-hook.jschanged
overrides/patchcore/message/html/action/reply.jschanged
lib/anchor-hook.jsView
@@ -7,8 +7,12 @@
77 return watch(current, (current) => {
88 if (current === name) {
99 window.requestAnimationFrame(() => {
1010 element.scrollIntoView()
11+
12+ // just make sure we still have the scroll position
13+ setTimeout(() => element.scrollIntoViewIfNeeded(), 400)
14+
1115 if (typeof cb === 'function') cb(element)
1216
1317 // HACK: due to a browser bug, sometimes the window scrolls down below the top bar
1418 // Why not just hack it!!!
overrides/patchcore/message/html/action/reply.jsView
@@ -1,13 +1,38 @@
11 var h = require('mutant/h')
22 var nest = require('depnest')
33
4-exports.needs = nest({'intl.sync.i18n': 'first'})
4+exports.needs = nest({
5+ 'intl.sync.i18n': 'first',
6+ 'app.navigate': 'first',
7+ 'message.sync.root': 'first'
58
9+})
10+
611 exports.gives = nest('message.html.action')
712
813 exports.create = (api) => {
914 const i18n = api.intl.sync.i18n
1015 return nest('message.html.action', function reply (msg) {
11- return h('a', { href: msg.key, anchor: 'reply' }, i18n('Reply'))
16+ return h('a', { href: msg.key, anchor: 'reply', 'ev-click': {handleEvent, api, msg} }, i18n('Reply'))
1217 })
1318 }
19+
20+function 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+
31+function 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+}

Built with git-ssb-web