Commit 0eb4374b336f60d5f9befb4eb57507275cd4f86c
abstract timestamp into it's own module.export
Ev Bogue committed on 5/26/2018, 5:13:26 PMParent: 86661677a7623472280bc05e563bb733054a0f01
Files changed
compose.js | changed |
render.js | changed |
tools.js | changed |
compose.js | ||
---|---|---|
@@ -89,15 +89,13 @@ | ||
89 | 89 | if (opts.updated) |
90 | 90 | msg.value.content.updated = opts.updated |
91 | 91 | |
92 | 92 | msg.value.content.text = textarea.value |
93 | - console.log(msg) | |
94 | - | |
93 | + | |
95 | 94 | if (opts.type == 'post') |
96 | 95 | var header = tools.header(msg) |
97 | 96 | 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}) | |
100 | 98 | var preview = h('div', |
101 | 99 | header, |
102 | 100 | h('div.message__content', tools.markdown(msg.value.content.text)), |
103 | 101 | h('button.btn', 'Publish', { |
@@ -107,12 +105,11 @@ | ||
107 | 105 | if(err) throw err |
108 | 106 | console.log('Published!', msg) |
109 | 107 | if (opts.type == 'update') { |
110 | 108 | var originalMessage = document.getElementById(opts.updated.substring(0,10)) |
111 | - console.log(originalMessage) | |
112 | 109 | opts.messageText = msg.value.content.text |
113 | 110 | 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}), | |
115 | 112 | h('div', tools.markdown(msg.value.content.text)) |
116 | 113 | ) |
117 | 114 | originalMessage.parentNode.replaceChild(newMessage, originalMessage) |
118 | 115 | newMessage.parentNode.appendChild(buttons) |
render.js | ||
---|---|---|
@@ -42,12 +42,11 @@ | ||
42 | 42 | |
43 | 43 | pull( |
44 | 44 | sbot.query({query: [{$filter: {value: {content: {type: 'update', updated: msg.key}}}}]}), |
45 | 45 | pull.drain(function (update) { |
46 | - var newTimestamp = h('span.timestamp', 'Edited: ', h('a', {href: '#' + update.key}, human(new Date(update.value.timestamp)))) | |
47 | 46 | var newMessage = h('div', tools.markdown(update.value.content.text)) |
48 | 47 | var latest = h('div.message__body', |
49 | - newTimestamp, | |
48 | + tools.timestamp(msg, {edited: true}), | |
50 | 49 | newMessage |
51 | 50 | ) |
52 | 51 | var r = message.childNodes.length - 2 |
53 | 52 | message.replaceChild(latest, message.childNodes[r]) |
tools.js | ||
---|---|---|
@@ -23,17 +23,26 @@ | ||
23 | 23 | } |
24 | 24 | return votes |
25 | 25 | } |
26 | 26 | |
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 | + | |
27 | 36 | module.exports.header = function (msg) { |
28 | 37 | return h('div.header', |
29 | 38 | h('span.avatar', |
30 | 39 | h('a', {href: '#' + msg.value.author}, |
31 | 40 | h('span.avatar--small', avatar.image(msg.value.author)), |
32 | 41 | avatar.name(msg.value.author) |
33 | 42 | ) |
34 | 43 | ), |
35 | - h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))), | |
44 | + exports.timestamp(msg), | |
36 | 45 | votes(msg) |
37 | 46 | ) |
38 | 47 | } |
39 | 48 |
Built with git-ssb-web