git ssb

16+

Dominic / patchbay



Tree: 4a873ea55bb2878927cf328e9044264bfdba5430

Files: 4a873ea55bb2878927cf328e9044264bfdba5430 / app / page / profile.js

2591 bytesRaw
1const nest = require('depnest')
2const Scroller = require('pull-scroll')
3const pull = require('pull-stream')
4const { h, watch, onceTrue, map, Dict, dictToCollection } = require('mutant')
5const next = require('pull-next-query')
6const Mutual = require('ssb-mutual')
7
8exports.gives = nest({
9 'app.html.menuItem': true,
10 'app.page.profile': true
11})
12
13exports.needs = nest({
14 'about.html.edit': 'first',
15 'about.obs.name': 'first',
16 'app.html.scroller': 'first',
17 'app.sync.goTo': 'first',
18 'contact.html.relationships': 'first',
19 'keys.sync.id': 'first',
20 'message.html.render': 'first',
21 'sbot.pull.stream': 'first',
22 'sbot.obs.connection': 'first'
23})
24
25exports.create = function (api) {
26 return nest({
27 'app.html.menuItem': menuItem,
28 'app.page.profile': profilePage
29 })
30
31 function menuItem () {
32 return h('a', {
33 'ev-click': () => api.app.sync.goTo(api.keys.sync.id())
34 }, '/profile')
35 }
36
37 function profilePage (location) {
38 const { feed: id } = location
39
40 var balances = Dict()
41 onceTrue(api.sbot.obs.connection, sbot => {
42 if (!sbot.links) throw new Error('where ma sbot.links at?!')
43 var mutual = Mutual.init(sbot)
44 mutual.getAccountBalances(id, (err, data) => {
45 if (err) console.log(err)
46 if (data == null) return
47
48 balances.set(data)
49 })
50 })
51
52 const profile = h('Profile', [
53 h('section.edit', api.about.html.edit(id)),
54 h('section.relationships', api.contact.html.relationships(id)),
55 h('section.credit', map(dictToCollection(balances), balance => {
56 return h('div', ['💰 ', balance.value, ' ', balance.key])
57 })),
58 h('section.activity', [
59 h('header', 'Activity')
60 // ideally the scroller content would go in here
61 ])
62 ])
63
64 var { container, content } = api.app.html.scroller({ prepend: profile })
65
66 const source = (opts) => api.sbot.pull.stream(s => next(s.query.read, opts, ['value', 'timestamp']))
67 const query = [{
68 $filter: {
69 value: {
70 timestamp: { $gt: 0 },
71 author: id
72 }
73 }
74 }]
75
76 pull(
77 source({ query, live: true, old: false }),
78 Scroller(container, content, render, true, false)
79 )
80
81 // how to handle when have scrolled past the start???
82
83 pull(
84 source({ query, reverse: true, limit: 50 }),
85 Scroller(container, content, render, false, false)
86 )
87
88 watch(api.about.obs.name(id), name => { container.title = '@' + name })
89 return container
90 }
91
92 function render (msg) {
93 return api.message.html.render(msg, { showTitle: true })
94 }
95}
96

Built with git-ssb-web