Files: f5dde01a771f059ca6c79e815d0d184dbc80523e / app / page / home.js
2480 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed } = require('mutant') |
3 | const {threadReduce} = require('ssb-reduce-stream') |
4 | const pull = require('pull-stream') |
5 | const isObject = require('lodash/isObject') |
6 | const isString = require('lodash/isString') |
7 | const last = require('lodash/last') |
8 | const get = require('lodash/get') |
9 | const More = require('hypermore') |
10 | const morphdom = require('morphdom') |
11 | |
12 | exports.gives = nest('app.page.home') |
13 | |
14 | exports.needs = nest({ |
15 | 'about.html.image': 'first', |
16 | 'about.obs.name': 'first', |
17 | 'app.html.nav': 'first', |
18 | 'sbot.pull.log': 'first', |
19 | 'history.sync.push': 'first', |
20 | 'keys.sync.id': 'first', |
21 | 'message.sync.unbox': 'first', |
22 | 'message.html.markdown': 'first', |
23 | 'translations.sync.strings': 'first', |
24 | 'state.obs.threads': 'first', |
25 | 'app.html.threadCard': 'first' |
26 | }) |
27 | |
28 | exports.create = (api) => { |
29 | return nest('app.page.home', function (location) { |
30 | // location here can expected to be: { page: 'home' } |
31 | var strings = api.translations.sync.strings() |
32 | |
33 | var container = h('div.container', []) |
34 | |
35 | function threadGroup (threads, obj, toContext, opts) { |
36 | // threads = a state object for all the types of threads |
37 | // obj = a map of keys to root ids, where key (channel | group | concatenated list of pubkeys) |
38 | // toContext = fn that derives the context of the group |
39 | // opts = { nameRecipients } |
40 | |
41 | var groupEl = h('div.threads') |
42 | for(var k in obj) { |
43 | var id = obj[k] |
44 | var thread = get(threads, ['roots', id]) |
45 | if(thread && thread.value) { |
46 | var el = api.app.html.threadCard(toContext(k, thread), thread, opts) |
47 | if(el) groupEl.appendChild(el) |
48 | } |
49 | } |
50 | return groupEl |
51 | } |
52 | |
53 | var threadsObs = api.state.obs.threads() |
54 | |
55 | var threadsHtmlObs = More( |
56 | threadsObs, |
57 | function render (threads) { |
58 | morphdom(container, |
59 | h('div.container', [ |
60 | //private section |
61 | h('section.updates -directMessage', [ |
62 | h('div.threads', |
63 | Object.keys(threads.roots).map(function (id) { |
64 | |
65 | return api.app.html |
66 | .threadCard(null, threads.roots[id], opts) |
67 | }) |
68 | ) |
69 | ]), |
70 | ]) |
71 | ) |
72 | return container |
73 | } |
74 | ) |
75 | |
76 | |
77 | return h('Page -home', [ |
78 | h('h1', 'Home'), |
79 | api.app.html.nav(), |
80 | threadsHtmlObs, |
81 | h('button', {'ev-click': threadsHtmlObs.more}, [strings.showMore]) |
82 | ]) |
83 | }) |
84 | } |
85 | |
86 |
Built with git-ssb-web