Files: 70bc98e1fcb76213a7b487d8e8b7a8f49cc45943 / modules_basic / avatar-profile.js
1741 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__friendss.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 | |
65 | return h('div.column.profile', |
66 | api.avatar_edit(id), |
67 | api.avatar_action(id), |
68 | h('div.profile__relationships.column', |
69 | h('strong', 'follows'), |
70 | follows_el, |
71 | h('strong', 'friends'), |
72 | friends_el, |
73 | h('strong', 'followers'), |
74 | followers_el |
75 | ) |
76 | ) |
77 | } |
78 | |
79 | } |
80 |
Built with git-ssb-web