Files: ee289a19dca6fefc3c9308225b6c429fdeb79ad6 / app / page / profile.js
1929 bytesRaw
1 | const nest = require('depnest') |
2 | const Scroller = require('pull-scroll') |
3 | const pull = require('pull-stream') |
4 | const { h, watch } = require('mutant') |
5 | const next = require('pull-next-query') |
6 | |
7 | exports.gives = nest({ |
8 | 'app.html.menuItem': true, |
9 | 'app.page.profile': true |
10 | }) |
11 | |
12 | exports.needs = nest({ |
13 | 'about.html.edit': 'first', |
14 | 'about.obs.name': 'first', |
15 | 'app.html.scroller': 'first', |
16 | 'app.sync.goTo': 'first', |
17 | 'contact.html.relationships': 'first', |
18 | 'keys.sync.id': 'first', |
19 | 'message.html.render': 'first', |
20 | 'sbot.pull.stream': 'first' |
21 | }) |
22 | |
23 | exports.create = function (api) { |
24 | return nest({ |
25 | 'app.html.menuItem': menuItem, |
26 | 'app.page.profile': profilePage |
27 | }) |
28 | |
29 | function menuItem () { |
30 | return h('a', { |
31 | 'ev-click': () => api.app.sync.goTo(api.keys.sync.id()) |
32 | }, '/profile') |
33 | } |
34 | |
35 | function profilePage (location) { |
36 | const { feed: id } = location |
37 | const profile = h('Profile', [ |
38 | h('section.edit', api.about.html.edit(id)), |
39 | h('section.relationships', api.contact.html.relationships(id)), |
40 | h('section.activity', [ |
41 | h('header', 'Activity') |
42 | // ideally the scroller content would go in here |
43 | ]) |
44 | ]) |
45 | |
46 | var { container, content } = api.app.html.scroller({ prepend: profile }) |
47 | |
48 | const source = (opts) => api.sbot.pull.stream(s => next(s.query.read, opts, ['value', 'timestamp'])) |
49 | const query = [{ |
50 | $filter: { |
51 | value: { |
52 | timestamp: { $gt: 0 }, |
53 | author: id |
54 | } |
55 | } |
56 | }] |
57 | |
58 | pull( |
59 | source({ query, live: true, old: false }), |
60 | Scroller(container, content, api.message.html.render, true, false) |
61 | ) |
62 | |
63 | // how to handle when have scrolled past the start??? |
64 | |
65 | pull( |
66 | source({ query, reverse: true, limit: 50 }), |
67 | Scroller(container, content, api.message.html.render, false, false) |
68 | ) |
69 | |
70 | watch(api.about.obs.name(id), name => { container.title = '@' + name }) |
71 | return container |
72 | } |
73 | } |
74 |
Built with git-ssb-web