git ssb

16+

Dominic / patchbay



Tree: 8ae0df05df1185783cf0ee77113ce4bcc4531bdd

Files: 8ae0df05df1185783cf0ee77113ce4bcc4531bdd / contact / html / relationships.js

2000 bytesRaw
1const nest = require('depnest')
2const pull = require('pull-stream')
3const { unique, drain } = pull
4const {
5 h, Array: MutantArray,
6 map, computed, when, dictToCollection
7} = require('mutant')
8
9exports.gives = nest('contact.html.relationships')
10
11exports.needs = nest({
12 about: {
13 'html.image': 'first',
14 'obs.name': 'first'
15 },
16 contact: {
17 obs: {
18 followers: 'first',
19 following: 'first'
20 }
21 // TODO add following
22 }
23})
24
25exports.create = function (api) {
26 return nest({
27 'contact.html.relationships': relationships
28 })
29
30 function relationships (id) {
31 var rawFollowing = api.contact.obs.following(id)
32 var rawFollowers = api.contact.obs.followers(id)
33
34 var friends = computed([rawFollowing, rawFollowers], (following, followers) => {
35 return [...following].filter(follow => followers.has(follow))
36 })
37
38 var following = computed([rawFollowing, friends], (following, friends) => {
39 return [...following].filter(follow => !friends.includes(follow))
40 })
41 var followers = computed([rawFollowers, friends], (followers, friends) => {
42 return [...followers].filter(follower => !friends.includes(follower))
43 })
44
45 function imageLink (id) {
46 return h('a',
47 { href: id, title: computed(api.about.obs.name(id), name => '@'+name) },
48 api.about.html.image(id)
49 )
50 }
51
52 // TOOD - split this into relationships, move top level stuff into Profile
53 return h('Relationships', [
54 h('header', 'Relationships'),
55 h('div.your-status', [
56 h('header', 'Your status'),
57 // h('section.action', api.contact.action(id))
58 ]),
59 h('div.friends', [
60 h('header', 'Friends'),
61 h('section', map(friends, imageLink))
62 ]),
63 h('div.follows', [
64 h('header', 'Follows'),
65 h('section', map(following, imageLink))
66 ]),
67 h('div.followers', [
68 h('header', 'Followers'),
69 h('section', map(followers, imageLink))
70 ])
71 ])
72 }
73
74}
75
76

Built with git-ssb-web