git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Commit 0eb4374b336f60d5f9befb4eb57507275cd4f86c

abstract timestamp into it's own module.export

Ev Bogue committed on 5/26/2018, 5:13:26 PM
Parent: 86661677a7623472280bc05e563bb733054a0f01

Files changed

compose.jschanged
render.jschanged
tools.jschanged
compose.jsView
@@ -89,15 +89,13 @@
8989 if (opts.updated)
9090 msg.value.content.updated = opts.updated
9191
9292 msg.value.content.text = textarea.value
93- console.log(msg)
94-
93+
9594 if (opts.type == 'post')
9695 var header = tools.header(msg)
9796 if (opts.type == 'update')
98- var header = h('div.timestamp', 'Edited: ', h('a', {href: msg.key}, human(new Date(msg.value.timestamp))))
99-
97+ var header = tools.timestamp(msg, {edited: true})
10098 var preview = h('div',
10199 header,
102100 h('div.message__content', tools.markdown(msg.value.content.text)),
103101 h('button.btn', 'Publish', {
@@ -107,12 +105,11 @@
107105 if(err) throw err
108106 console.log('Published!', msg)
109107 if (opts.type == 'update') {
110108 var originalMessage = document.getElementById(opts.updated.substring(0,10))
111- console.log(originalMessage)
112109 opts.messageText = msg.value.content.text
113110 var newMessage = h('div.message__body',
114- h('div.timestamp', 'Edited: ', h('a', {href: msg.key}, human(new Date(msg.value.timestamp)))),
111+ tools.timestamp(msg, {edited: true}),
115112 h('div', tools.markdown(msg.value.content.text))
116113 )
117114 originalMessage.parentNode.replaceChild(newMessage, originalMessage)
118115 newMessage.parentNode.appendChild(buttons)
render.jsView
@@ -42,12 +42,11 @@
4242
4343 pull(
4444 sbot.query({query: [{$filter: {value: {content: {type: 'update', updated: msg.key}}}}]}),
4545 pull.drain(function (update) {
46- var newTimestamp = h('span.timestamp', 'Edited: ', h('a', {href: '#' + update.key}, human(new Date(update.value.timestamp))))
4746 var newMessage = h('div', tools.markdown(update.value.content.text))
4847 var latest = h('div.message__body',
49- newTimestamp,
48+ tools.timestamp(msg, {edited: true}),
5049 newMessage
5150 )
5251 var r = message.childNodes.length - 2
5352 message.replaceChild(latest, message.childNodes[r])
tools.jsView
@@ -23,17 +23,26 @@
2323 }
2424 return votes
2525 }
2626
27+module.exports.timestamp = function (msg, edited) {
28+ var timestamp
29+ if (edited)
30+ timestamp = h('span.timestamp', 'Edited: ', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp))))
31+ else
32+ timestamp = h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp))))
33+ return timestamp
34+}
35+
2736 module.exports.header = function (msg) {
2837 return h('div.header',
2938 h('span.avatar',
3039 h('a', {href: '#' + msg.value.author},
3140 h('span.avatar--small', avatar.image(msg.value.author)),
3241 avatar.name(msg.value.author)
3342 )
3443 ),
35- h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
44+ exports.timestamp(msg),
3645 votes(msg)
3746 )
3847 }
3948

Built with git-ssb-web