git ssb

16+

Dominic / patchbay



Commit 5e399826faea89305f911f9f2fb8a9509f9a0319

move timestamp to message author component, fix raw button

Michael Williams committed on 12/22/2016, 11:35:36 AM
Parent: e69d724b2b71385a2c73b9539acf9aee8dc0926b

Files changed

modules_basic/message-header.jschanged
modules_basic/message.jschanged
modules_basic/timestamp.jschanged
modules_basic/timestamp.mcssadded
modules_extra/raw.jschanged
modules_basic/message-header.jsView
@@ -2,11 +2,14 @@
22 var Path = require('path')
33 var h = require('../h')
44
55 exports.needs = {
6- avatar: 'first',
6 + avatar_link: 'first',
7 + avatar_image: 'first',
8 + avatar_name: 'first',
79 message_meta: 'map',
8- message_link: 'first'
10 + message_link: 'first',
11 + timestamp: 'first'
912 }
1013
1114 exports.gives = {
1215 message_header: true,
@@ -19,10 +22,16 @@
1922 mcss: () => fs.readFileSync(Path.join(__dirname, 'message-header.mcss'))
2023 }
2124
2225 function message_header (msg) {
26 + var { value } = msg
27 + var { author } = value
2328 return h('MessageHeader', [
24- h('section.author', api.avatar(msg.value.author, 'thumbnail')),
29 + h('section.author', [
30 + api.avatar_link(author, api.avatar_image(author, 'thumbnail')),
31 + api.avatar_link(author, api.avatar_name(author)),
32 + api.timestamp(msg)
33 + ]),
2534 h('section.meta', api.message_meta(msg))
2635 ])
2736 }
2837 }
modules_basic/message.jsView
@@ -26,8 +26,9 @@
2626 }
2727
2828 function message_render (msg, sbot) {
2929 var content = api.message_content_mini(msg)
30 + // TODO re-enable
3031 //if(content) return mini(msg, content)
3132
3233 var content = api.message_content(msg)
3334 if(!content) return mini(msg, message_content_mini_fallback(msg))
@@ -52,9 +53,9 @@
5253 // unless in an input
5354 if (ev.target.nodeName === 'INPUT'
5455 || ev.target.nodeName === 'TEXTAREA') return
5556
56- // HACK!
57 + // HACK! (mw)
5758 // there's no exported api to open a new tab. :/
5859 // it's only done in `app.js` module in an`onhashchange` handler.
5960 // sooooooo yeah this shit:
6061 var wtf = h('a', { href: `#${msg.key}` })
modules_basic/timestamp.jsView
@@ -1,28 +1,47 @@
1-var h = require('hyperscript')
1 +var fs = require('fs')
2 +var Path = require('path')
3 +var h = require('../h')
24 var human = require('human-time')
35
46 exports.needs = {}
57
6-exports.gives = 'message_meta'
8 +exports.gives = {
9 + timestamp: true,
10 + mcss: true
11 +}
712
813 exports.create = function () {
9-
10- function updateTimestampEl(el) {
11- el.firstChild.nodeValue = human(new Date(el.timestamp))
12- return el
13- }
14-
1514 setInterval(function () {
16- var els = [].slice.call(document.querySelectorAll('.timestamp'))
15 + var els = [].slice.call(document.querySelectorAll('.Timestamp'))
1716 els.forEach(updateTimestampEl)
1817 }, 60e3)
1918
20- return function (msg) {
21- return updateTimestampEl(h('a.enter.timestamp', {
22- href: '#'+msg.key,
23- timestamp: msg.value.timestamp,
24- title: new Date(msg.value.timestamp)
25- }, ''))
19 + return {
20 + timestamp,
21 + mcss: () => fs.readFileSync(Path.join(__dirname, 'timestamp.mcss'))
2622 }
2723
24 + function updateTimestampEl (el) {
25 + var timestamp = Number(el.getAttribute('data-timestamp'))
26 + var display = human(new Date(timestamp))
27 + el.querySelector('a').firstChild.nodeValue = display
28 + return el
29 + }
30 +
31 + function timestamp (msg) {
32 + var { key, value } = msg
33 + var { timestamp } = value
34 + var el = h('Timestamp', {
35 + attributes: {
36 + 'data-timestamp': timestamp
37 + }
38 + }, [
39 + h('a', {
40 + href: `#${key}`,
41 + title: new Date(timestamp)
42 + }, '')
43 + ])
44 + updateTimestampEl(el)
45 + return el
46 + }
2847 }
modules_basic/timestamp.mcssView
@@ -1,0 +1,5 @@
1 +Timestamp {
2 + a {
3 +
4 + }
5 +}
modules_extra/raw.jsView
@@ -28,10 +28,11 @@
2828 return h('input', {
2929 type: 'checkbox',
3030 title: 'View Data',
3131 onclick: function () {
32- var msgEl = this.parentNode.parentNode.parentNode
33- var msgContentEl = msgEl.querySelector('.message_content')
32 + // HACK (mw) yo we need a better way to replace the content
33 + var msgEl = this.parentNode.parentNode.parentNode.parentNode
34 + var msgContentEl = msgEl.querySelector('.Message > section.-content')
3435 if (this.checked) {
3536 // move away the content
3637 while (el = msgContentEl.firstChild)
3738 tmp.appendChild(el)

Built with git-ssb-web