git ssb

1+

Daan Patchwork / patchwork



Tree: 81788a3aabacb716a48ed9cff993466e6eeffb3b

Files: 81788a3aabacb716a48ed9cff993466e6eeffb3b / lib / depject / channel / html / preview.js

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

Built with git-ssb-web