git ssb

16+

Dominic / patchbay



Tree: 4441fae4d0d265267896434addfea2900d7f5154

Files: 4441fae4d0d265267896434addfea2900d7f5154 / contact / html / relationships.js

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

Built with git-ssb-web