git ssb

16+

Dominic / patchbay



Tree: ed0d0518717fe16a686399588766fb35b3e6e37a

Files: ed0d0518717fe16a686399588766fb35b3e6e37a / app / page / profile.js

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

Built with git-ssb-web