git ssb

7+

dinoworm 🐛 / patchcore



Commit b58dd46b8f88f0917c480faf8286bdd209933739

add timestamp using an observable

wooo!
Michael Williams committed on 2/13/2017, 9:24:28 AM
Parent: 692e5b60efe4cf58df0598ab494c553c8910a017

Files changed

components/message/timestamp.jschanged
observables/timeAgo.jsadded
package.jsonchanged
plugs/message_layout/default.jschanged
plugs/message_layout/mini.jschanged
components/message/timestamp.jsView
@@ -1,16 +1,17 @@
11 const h = require('mutant/h')
2 +const nest = require('depnest')
23
3-exports.gives = {
4- message_components: true
5-}
4 +exports.gives = nest('message.timestamp')
5 +exports.needs = nest('obs.timeAgo', 'first')
66
77 exports.create = function (api) {
8- return {
9- message_components
10- }
8 + return nest('message.timestamp', timestamp)
119
12- function message_components (msg) {
13- return h('div', new Date(msg.value.timestamp).toString())
10 + function timestamp (msg) {
11 + return h('a.Timestamp', {
12 + href: msg.key,
13 + title: new Date(msg.value.timestamp)
14 + }, api.obs.timeAgo(msg.value.timestamp))
1415 }
1516 }
1617
observables/timeAgo.jsView
@@ -1,0 +1,34 @@
1 +const Value = require('mutant/value')
2 +const computed = require('mutant/computed')
3 +const nest = require('depnest')
4 +const human = require('human-time')
5 +
6 +exports.gives = nest('obs.timeAgo')
7 +
8 +exports.create = function (api) {
9 + return nest('obs.timeAgo', timeAgo)
10 +
11 + function timeAgo (timestamp) {
12 + var timer
13 + var value = Value(Time(timestamp))
14 + return computed([value], (a) => a, {
15 + onListen: () => {
16 + timer = setInterval(refresh, 5e3)
17 + refresh()
18 + },
19 + onUnlisten: () => {
20 + clearInterval(timer)
21 + }
22 + })
23 +
24 + function refresh () {
25 + value.set(Time(timestamp))
26 + }
27 + }
28 +}
29 +
30 +function Time (timestamp) {
31 + return human(new Date(timestamp))
32 + .replace(/minute/, 'min')
33 + .replace(/second/, 'sec')
34 +}
package.jsonView
@@ -25,10 +25,12 @@
2525 "homepage": "https://github.com/ssbc/patchcore#readme",
2626 "dependencies": {
2727 "bulk-require": "^1.0.0",
2828 "bulkify": "^1.4.2",
29 + "depnest": "^1.0.2",
2930 "emoji-named-characters": "^1.0.2",
3031 "es2040": "^1.2.4",
32 + "human-time": "0.0.1",
3133 "mutant": "^3.13.2",
3234 "pull-abortable": "^4.1.0",
3335 "pull-reconnect": "0.0.3",
3436 "pull-stream": "^3.5.0",
plugs/message_layout/default.jsView
@@ -3,9 +3,12 @@
33 exports.needs = {
44 message_backlinks: 'first',
55 message_author: 'first',
66 message_meta: 'map',
7- message_action: 'map'
7 + message_action: 'map',
8 + message: {
9 + timestamp: 'first'
10 + }
811 }
912
1013 exports.gives = {
1114 message_layout: true
@@ -21,8 +24,9 @@
2124 return h('div', {
2225 classList: 'Message'
2326 }, [
2427 h('header.author', {}, api.message_author(msg)),
28 + h('section.timestamp', {}, api.message.timestamp(msg)),
2529 h('section.title', {}, opts.title),
2630 h('section.meta', {}, api.message_meta(msg)),
2731 h('section.content', {}, opts.content),
2832 h('section.raw-content'),
plugs/message_layout/mini.jsView
@@ -2,9 +2,12 @@
22
33 exports.needs = {
44 message_backlinks: 'first',
55 message_author: 'first',
6- message_meta: 'map'
6 + message_meta: 'map',
7 + message: {
8 + timestamp: 'first'
9 + }
710 }
811
912 exports.gives = {
1013 message_layout: true
@@ -20,8 +23,9 @@
2023 return h('div', {
2124 classList: 'Message -mini'
2225 }, [
2326 h('header.author', {}, api.message_author(msg, { size: 'mini' })),
27 + h('section.timestamp', {}, api.message.timestamp(msg)),
2428 h('section.meta', {}, api.message_meta(msg)),
2529 h('section.content', {}, opts.content),
2630 h('section.raw-content')
2731 ])

Built with git-ssb-web