git ssb

2+

mixmix / ticktack



Tree: e2fb4d766af3a45d510a0558e410b04dd3366e13

Files: e2fb4d766af3a45d510a0558e410b04dd3366e13 / app / page / addressBook.js

2681 bytesRaw
1const nest = require('depnest')
2const { h, Value, computed, map } = require('mutant')
3const pull = require('pull-stream')
4
5exports.gives = nest('app.page.addressBook')
6
7//declare consts to avoid magic-string errors
8const FRIENDS = 'friends'
9const FOLLOWING = 'following'
10const FOLLOWERS = 'followers'
11const SEARCH = 'search'
12
13exports.needs = nest({
14 'about.html.avatar': 'first',
15 'about.async.suggest': 'first',
16 'about.obs.name': 'first',
17 'app.html.topNav': 'first',
18 // 'app.html.scroller': 'first',
19 'app.html.sideNav': 'first',
20 'app.html.topNav': 'first',
21 'contact.html.follow': 'first',
22 'contact.obs.relationships': 'first',
23 'history.sync.push': 'first',
24 'keys.sync.id': 'first',
25 'translations.sync.strings': 'first',
26})
27
28exports.create = (api) => {
29 return nest('app.page.addressBook', function (location) {
30 // location here can expected to be: { page: 'addressBook'}
31
32 const strings = api.translations.sync.strings()
33 const myKey = api.keys.sync.id()
34 const relationships = api.contact.obs.relationships(myKey)
35
36 const SECTIONS = [FRIENDS, FOLLOWING, FOLLOWERS, SEARCH]
37 const section = location.section || FRIENDS
38 if (!SECTIONS.includes(section)) throw new Error('AddressBook location must include valid section, got:', location)
39
40 const input = Value()
41
42 const suggester = api.about.async.suggest()
43 const users = computed([relationships, input], (relationships, input) => {
44 if (section === SEARCH)
45 return suggester(input)
46 else {
47 const sectionRels = relationships[section]
48 if (!input) {
49 return sectionRels // show all e.g. friends
50 .reverse()
51 .map(id => { return { id, title: api.about.obs.name(id) } })
52 }
53 else { // show suggestions, and filter just the ones we want e.g. friends
54 return suggester(input, relationships.followers) // add extraIds to suggester
55 .filter(user => sectionRels.includes(user.id))
56 }
57 }
58 })
59
60 const goTo = (loc) => () => api.history.sync.push(loc)
61
62 return h('Page -addressBook', [
63 api.app.html.sideNav(location, relationships),
64 h('Scroller.content', [
65 h('section.top', [
66 api.app.html.topNav(location, input),
67 ]),
68 h('section.content', [
69 h('div.results', map(users, user => {
70 return h('div.result', { 'ev-click': goTo({page: 'userShow', feed: user.id}) }, [
71 api.about.html.avatar(user.id),
72 h('div.alias', user.title),
73 // h('pre.key', user.id),
74 api.contact.html.follow(user.id)
75 ])
76 })),
77 ])
78 ])
79 ])
80 })
81}
82
83

Built with git-ssb-web