git ssb

2+

mixmix / ticktack



Tree: f5dde01a771f059ca6c79e815d0d184dbc80523e

Files: f5dde01a771f059ca6c79e815d0d184dbc80523e / app / page / home.js

2480 bytesRaw
1const nest = require('depnest')
2const { h, computed } = require('mutant')
3const {threadReduce} = require('ssb-reduce-stream')
4const pull = require('pull-stream')
5const isObject = require('lodash/isObject')
6const isString = require('lodash/isString')
7const last = require('lodash/last')
8const get = require('lodash/get')
9const More = require('hypermore')
10const morphdom = require('morphdom')
11
12exports.gives = nest('app.page.home')
13
14exports.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
28exports.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