Files: b62ecd6f843b26f37e70c7b6d65c71db35bbf922 / modules / avatar-profile.js
1739 bytesRaw
1 | var h = require('hyperscript') |
2 | var pull = require('pull-stream') |
3 | |
4 | exports.needs = { |
5 | avatar_image_link: 'first', |
6 | avatar_action: 'map', |
7 | avatar_edit: 'first', |
8 | follows: 'first', |
9 | followers: 'first' |
10 | } |
11 | |
12 | exports.gives = 'avatar_profile' |
13 | |
14 | function streamToList(stream, el) { |
15 | pull( |
16 | stream, |
17 | pull.drain(function (item) { |
18 | if(item) el.appendChild(item) |
19 | }) |
20 | ) |
21 | return el |
22 | } |
23 | |
24 | exports.create = function (api) { |
25 | |
26 | function image_link (id) { |
27 | return api.avatar_image_link(id, 'thumbnail') |
28 | } |
29 | |
30 | return function (id) { |
31 | |
32 | var follows_el = h('div.profile__follows.wrap') |
33 | var friends_el = h('div.profile__friends.wrap') |
34 | var followers_el = h('div.profile__followers.wrap') |
35 | var a, b |
36 | |
37 | pull(api.follows(id), pull.unique(), pull.collect(function (err, ary) { |
38 | a = ary || []; next() |
39 | })) |
40 | pull(api.followers(id), pull.unique(), pull.collect(function (err, ary) { |
41 | b = ary || {}; next() |
42 | })) |
43 | |
44 | function next () { |
45 | if(!(a && b)) return |
46 | var _c = [], _a = [], _b = [] |
47 | |
48 | a.forEach(function (id) { |
49 | if(!~b.indexOf(id)) _a.push(id) |
50 | else _c.push(id) |
51 | }) |
52 | b.forEach(function (id) { |
53 | if(!~_c.indexOf(id)) _b.push(id) |
54 | }) |
55 | function add (ary, el) { |
56 | ary.forEach(function (id) { el.appendChild(image_link(id)) }) |
57 | } |
58 | |
59 | add(_a, follows_el) |
60 | add(_c, friends_el) |
61 | add(_b, followers_el) |
62 | } |
63 | |
64 | return h('div.column.profile', |
65 | api.avatar_edit(id), |
66 | api.avatar_action(id), |
67 | h('div.profile__relationships.column', |
68 | h('strong', 'follows'), |
69 | follows_el, |
70 | h('strong', 'friends'), |
71 | friends_el, |
72 | h('strong', 'followers'), |
73 | followers_el |
74 | ) |
75 | ) |
76 | } |
77 | } |
78 | |
79 |
Built with git-ssb-web