Files: 78d39dc669df20b2f705b64f5de61c54906da3d2 / modules_basic / avatar / profile.js
2247 bytesRaw
1 | const fs = require('fs') |
2 | const h = require('../../h') |
3 | const pull = require('pull-stream') |
4 | const { unique, drain } = pull |
5 | const { |
6 | Array: MutantArray, |
7 | map, computed, when, dictToCollection |
8 | } = require('@mmckegg/mutant') |
9 | |
10 | |
11 | exports.needs = { |
12 | avatar_image_link: 'first', |
13 | avatar_action: 'map', |
14 | avatar_edit: 'first', |
15 | follows: 'first', |
16 | followers: 'first' |
17 | } |
18 | |
19 | exports.gives = { |
20 | avatar_profile: true, |
21 | mcss: true |
22 | } |
23 | |
24 | exports.create = function (api) { |
25 | return { |
26 | avatar_profile, |
27 | mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') |
28 | } |
29 | |
30 | function avatar_profile (id) { |
31 | |
32 | var rawFollows = MutantArray() |
33 | var rawFollowers = MutantArray() |
34 | var friends = computed([rawFollows, rawFollowers], (follows, followers) => { |
35 | return follows.filter(follow => followers.includes(follow)) |
36 | }) |
37 | |
38 | var follows = computed([rawFollows, friends], (follows, friends) => { |
39 | return follows.filter(follow => !friends.includes(follow)) |
40 | }) |
41 | var followers = computed([rawFollowers, friends], (followers, friends) => { |
42 | return followers.filter(follower => !friends.includes(follower)) |
43 | }) |
44 | |
45 | pull( |
46 | api.follows(id), |
47 | unique(), |
48 | drain( |
49 | peer => rawFollows.push(peer), |
50 | (err, data) => console.log('follows drain done', err, data) |
51 | ) |
52 | ) |
53 | pull( |
54 | api.followers(id), |
55 | unique(), |
56 | drain( |
57 | peer => rawFollowers.push(peer), |
58 | (err, data) => console.log('followers drain done', err, data) |
59 | ) |
60 | ) |
61 | |
62 | return h('Profile', [ |
63 | h('section.edit', api.avatar_edit(id)), |
64 | h('section.relationships', [ |
65 | h('header', 'Relationships'), |
66 | h('div.your-status', [ |
67 | h('header', 'Your status'), |
68 | h('section.action', api.avatar_action(id)) |
69 | ]), |
70 | h('div.friends', [ |
71 | h('header', 'Friends'), |
72 | h('section', map(friends, id => api.avatar_image_link(id))) |
73 | ]), |
74 | h('div.follows', [ |
75 | h('header', 'Follows'), |
76 | h('section', map(follows, id => api.avatar_image_link(id))) |
77 | ]), |
78 | h('div.followers', [ |
79 | h('header', 'Followers'), |
80 | h('section', map(followers, id => api.avatar_image_link(id))) |
81 | ]) |
82 | ]) |
83 | ]) |
84 | } |
85 | |
86 | } |
87 |
Built with git-ssb-web