git ssb

2+

mixmix / ticktack



Commit 7e329243c50961d1697aed2c65b864bd8fdee622

basic home screen

Dominic Tarr committed on 8/9/2017, 3:52:49 AM
Parent: 2af44d4aee39e0426aed47a2aa2414eb969d097b

Files changed

app/page/home.jschanged
app/page/home.jsView
@@ -1,23 +1,82 @@
11 const nest = require('depnest')
22 const { h } = require('mutant')
3+const {threadReduce} = require('ssb-reduce-stream')
4+const pull = require('pull-stream')
35
46 exports.gives = nest('app.page.home')
57
68 exports.needs = nest({
7- 'app.sync.goTo': 'first'
9+ 'app.sync.goTo': 'first',
10+ 'feed.pull.public': 'first'
811 })
912
13+function firstLine (text) {
14+ if(text.length < 80 && !~text.indexOf('\n')) return text
15+
16+ return text.split('\n')[0].substring(0, 80)
17+}
18+
1019 exports.create = (api) => {
1120 return nest('app.page.home', home)
1221
1322 function home (location) {
1423 // location here can expected to be: { page: 'home' }
1524 const { goTo } = api.app.sync
1625
26+ var div = h('div', [])
27+
28+ function subject (msg) {
29+ return firstLine(msg.content.subject || msg.content.text)
30+ }
31+
32+ function item (name, thread) {
33+ var reply = thread.replies && thread.replies[thread.replies.length-1]
34+ if(!thread.value) {
35+
36+ }
37+ if(!thread.value) return
38+ return h('div', [
39+ h('h2', name),
40+ h('div.subject', [subject(thread.value)]),
41+ reply ? h('div.reply', [subject(reply.value)]) : null
42+ ]
43+ )
44+ }
45+
46+ pull(
47+ api.feed.pull.public({reverse: true, limit: 1000}),
48+ pull.through(console.log),
49+ pull.collect(function (err, messages) {
50+ var threads = messages.reduce(threadReduce, null)
51+ for(var k in threads.channels) {
52+ var id = threads.channels[k]
53+ if(!threads.roots[id]) throw new Error('missing thread:'+id+' for channel:'+k)
54+ var el = item(k, threads.roots[id])
55+ if(el)
56+ div.appendChild(el)
57+ }
58+ })
59+ )
60+
61+ return div
62+
63+
1764 return h('div', [
1865 h('h1', 'Home'),
1966 h('div', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'),
2067 h('div', { 'ev-click': () => goTo({ type: 'group', key: '%sadlkjas;lkdjas' }) }, 'Group')
2168 ])
2269 }
2370 }
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+

Built with git-ssb-web