Files: fcfbae5c6e775a1476eccf472297cdd5828a686e / modules / channel / html / preview.js
2097 bytesRaw
1 | var nest = require('depnest') |
2 | var h = require('mutant/h') |
3 | var when = require('mutant/when') |
4 | var computed = require('mutant/computed') |
5 | var send = require('mutant/send') |
6 | |
7 | exports.needs = nest({ |
8 | 'about.obs.name': 'first', |
9 | 'about.html.image': 'first', |
10 | 'keys.sync.id': 'first', |
11 | 'sheet.display': 'first', |
12 | 'app.navigate': 'first', |
13 | 'intl.sync.i18n': 'first', |
14 | 'intl.sync.i18n_n': 'first', |
15 | 'sheet.profiles': 'first', |
16 | 'channel.html.subscribeToggle': 'first', |
17 | 'channel.sync.normalize': 'first', |
18 | 'channel.obs.subscribers': 'first', |
19 | 'contact.obs.following': 'first' |
20 | }) |
21 | |
22 | exports.gives = nest('channel.html.preview') |
23 | |
24 | exports.create = function (api) { |
25 | const i18n = api.intl.sync.i18n |
26 | const plural = api.intl.sync.i18n_n |
27 | |
28 | return nest('channel.html.preview', function (id) { |
29 | var yourId = api.keys.sync.id() |
30 | var channel = api.channel.sync.normalize(id) |
31 | var href = '#' + channel |
32 | var subscribers = api.channel.obs.subscribers(id) |
33 | var following = api.contact.obs.following(yourId) |
34 | var followingSubscribers = computed([subscribers, following], (a, b) => { |
35 | return a.filter(v => b.includes(v)) |
36 | }) |
37 | var followingSubscriberCount = computed(followingSubscribers, x => x.length) |
38 | |
39 | return h('ProfilePreview', [ |
40 | h('header', [ |
41 | h('div.main', [ |
42 | h('div.title', [ |
43 | h('h1', [ |
44 | h('a', {href, 'ev-click': () => api.app.navigate(href)}, [href]) |
45 | ]), |
46 | h('div.meta', [ |
47 | api.channel.html.subscribeToggle(channel) |
48 | ]) |
49 | ]) |
50 | ]) |
51 | ]), |
52 | |
53 | when(followingSubscriberCount, |
54 | h('section -mutualFriends', [ |
55 | h('a', { |
56 | href: '#', |
57 | 'ev-click': send(displaySubscribingFriends, followingSubscribers) |
58 | }, [ |
59 | '👥 ', computed(['You follow %s people that subscribe to this channel.', followingSubscriberCount], plural) |
60 | ]) |
61 | ]) |
62 | ) |
63 | ]) |
64 | }) |
65 | |
66 | function displaySubscribingFriends (profiles) { |
67 | api.sheet.profiles(profiles, i18n('People you follow that subscribe to this channel')) |
68 | } |
69 | } |
70 |
Built with git-ssb-web