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