Commit 7e329243c50961d1697aed2c65b864bd8fdee622
basic home screen
Dominic Tarr committed on 8/9/2017, 3:52:49 AMParent: 2af44d4aee39e0426aed47a2aa2414eb969d097b
Files changed
app/page/home.js | changed |
app/page/home.js | ||
---|---|---|
@@ -1,23 +1,82 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | 2 | const { h } = require('mutant') |
3 | +const {threadReduce} = require('ssb-reduce-stream') | |
4 | +const pull = require('pull-stream') | |
3 | 5 | |
4 | 6 | exports.gives = nest('app.page.home') |
5 | 7 | |
6 | 8 | exports.needs = nest({ |
7 | - 'app.sync.goTo': 'first' | |
9 | + 'app.sync.goTo': 'first', | |
10 | + 'feed.pull.public': 'first' | |
8 | 11 | }) |
9 | 12 | |
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 | + | |
10 | 19 | exports.create = (api) => { |
11 | 20 | return nest('app.page.home', home) |
12 | 21 | |
13 | 22 | function home (location) { |
14 | 23 | // location here can expected to be: { page: 'home' } |
15 | 24 | const { goTo } = api.app.sync |
16 | 25 | |
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 | + | |
17 | 64 | return h('div', [ |
18 | 65 | h('h1', 'Home'), |
19 | 66 | h('div', { 'ev-click': () => goTo({ page: 'home' }) }, 'Home'), |
20 | 67 | h('div', { 'ev-click': () => goTo({ type: 'group', key: '%sadlkjas;lkdjas' }) }, 'Group') |
21 | 68 | ]) |
22 | 69 | } |
23 | 70 | } |
71 | + | |
72 | + | |
73 | + | |
74 | + | |
75 | + | |
76 | + | |
77 | + | |
78 | + | |
79 | + | |
80 | + | |
81 | + | |
82 | + |
Built with git-ssb-web