git ssb

16+

Dominic / patchbay



Commit b27c7da727a6667120dbf9108cecbef28faa8060

refactor message layouts datasets out into message decorators

mix irving committed on 4/2/2017, 11:37:29 AM
Parent: 2f61b5b3290364b166a9c8fe8deaa025e501e8b9

Files changed

main/sync/catch-keyboard-shortcut.jschanged
message/html/layout/default.jschanged
message/html/layout/mini.jschanged
message/html/decorate/data-root.jsadded
message/html/decorate/data-text.jsadded
main/sync/catch-keyboard-shortcut.jsView
@@ -91,24 +91,24 @@
9191
9292 // this uses a crudely exported nav api
9393 const search = document.querySelector('input[type=search]')
9494
95- const { root, key } = msg.dataset
96- if (!root) return search.go(key)
95+ const { root, id } = msg.dataset
96+ if (!root) return search.go(id)
9797
9898 search.go(root)
99- scrollDownToMessage(key, tabs)
99+ scrollDownToMessage(id, tabs)
100100 }
101101
102-function scrollDownToMessage (key, tabs) {
102+function scrollDownToMessage (id, tabs) {
103103 tabs.get(tabs.selected[0]).firstChild.scroll('first')
104104 locateKey()
105105
106106 function locateKey () {
107107 const msg = tabs.get(tabs.selected[0]).firstChild.scroll(1)
108108 if (msg === undefined) return setTimeout(locateKey, 100)
109109
110- if (msg && msg.dataset && msg.dataset.key === key) return
110+ if (msg && msg.dataset && msg.dataset.id === id) return
111111
112112 locateKey()
113113 }
114114 }
message/html/layout/default.jsView
@@ -21,16 +21,13 @@
2121 if (!(opts.layout === undefined || opts.layout === 'default')) return
2222
2323 var rawMessage = Value(null)
2424
25- const attributes = {
26- tabindex: '0', // needed to be able to navigate and show focus()
27- 'data-key': msg.key,
28- 'data-text': msg.value.content.text
29- }
30- if (msg.value.content.root) attributes['data-root'] = msg.value.content.root
31-
32- return h('Message', { attributes }, [
25+ return h('Message', {
26+ attributes: {
27+ tabindex: '0' // needed to be able to navigate and show focus()
28+ }
29+ }, [
3330 h('section.avatar', {}, api.about.html.image(msg.value.author)),
3431 h('section.timestamp', {}, api.message.html.timestamp(msg)),
3532 h('header.author', {}, api.message.html.author(msg)),
3633 h('section.meta', {}, api.message.html.meta(msg, { rawMessage })),
message/html/layout/mini.jsView
@@ -17,10 +17,9 @@
1717 if (opts.layout !== 'mini') return
1818
1919 var rawMessage = Value(null)
2020
21- return h('div', {
22- classList: 'Message -mini',
21+ return h('Message -mini', {
2322 attributes: {
2423 tabindex: '0'
2524 }
2625 }, [
message/html/decorate/data-root.jsView
@@ -1,0 +1,10 @@
1+const nest = require('depnest')
2+
3+exports.gives = nest('message.html.decorate')
4+
5+exports.create = (api) => {
6+ return nest('message.html.decorate', function (element, { msg }) {
7+ if (msg.value.content.root) element.dataset.root = msg.value.content.root
8+ return element
9+ })
10+}
message/html/decorate/data-text.jsView
@@ -1,0 +1,11 @@
1+const nest = require('depnest')
2+
3+exports.gives = nest('message.html.decorate')
4+
5+exports.create = (api) => {
6+ return nest('message.html.decorate', function (element, { msg }) {
7+ if (msg.value.content.text) element.dataset.text = msg.value.content.text
8+ return element
9+ })
10+}
11+

Built with git-ssb-web