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