Files: c14e98624b1ae5d90235af8556d3f3d82510130d / modules_basic / avatar / profile.js
1724 bytesRaw
1 | const fs = require('fs') |
2 | const h = require('../../h') |
3 | const pull = require('pull-stream') |
4 | const { unique, collect, drain } = pull |
5 | |
6 | |
7 | exports.needs = { |
8 | avatar_image_link: 'first', |
9 | avatar_action: 'map', |
10 | avatar_edit: 'first', |
11 | follows: 'first', |
12 | followers: 'first' |
13 | } |
14 | |
15 | exports.gives = { |
16 | avatar_profile: true, |
17 | mcss: true |
18 | } |
19 | |
20 | exports.create = function (api) { |
21 | return { |
22 | avatar_profile, |
23 | mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') |
24 | } |
25 | |
26 | function avatar_profile (id) { |
27 | |
28 | var friends_el = h('div.friends', [ |
29 | h('header', 'Friends') |
30 | ]) |
31 | var follows_el = h('div.follows', [ |
32 | h('header', 'Follows') |
33 | ]) |
34 | var followers_el = h('div.followers', [ |
35 | h('header', 'Followers') |
36 | ]) |
37 | var a, b |
38 | |
39 | pull( |
40 | api.follows(id), |
41 | unique(), |
42 | collect((err, ary = []) => { |
43 | a = ary; next() |
44 | }) |
45 | ) |
46 | pull( |
47 | api.followers(id), |
48 | unique(), |
49 | collect((err, ary = {}) => { |
50 | b = ary; next() |
51 | }) |
52 | ) |
53 | |
54 | function next () { |
55 | if(!(a && b)) return |
56 | var _c = [], _a = [], _b = [] |
57 | |
58 | a.forEach(id => { |
59 | if(!~b.indexOf(id)) _a.push(id) |
60 | else _c.push(id) |
61 | }) |
62 | b.forEach(id => { |
63 | if(!~_c.indexOf(id)) _b.push(id) |
64 | }) |
65 | |
66 | add(_c, friends_el) |
67 | add(_a, follows_el) |
68 | add(_b, followers_el) |
69 | |
70 | function add (ary, el) { |
71 | ary.forEach(id => el.appendChild(api.avatar_image_link(id)) ) |
72 | } |
73 | } |
74 | |
75 | |
76 | return h('Profile', [ |
77 | h('section.edit', api.avatar_edit(id)), |
78 | h('section.action', api.avatar_action(id)), |
79 | h('section.relationships', [ |
80 | friends_el, |
81 | follows_el, |
82 | followers_el |
83 | ]) |
84 | ]) |
85 | } |
86 | |
87 | } |
88 |
Built with git-ssb-web