git ssb

2+

mixmix / ticktack



Tree: 3f20b6a02893dcb23a3239a1e9623b8234222ba7

Files: 3f20b6a02893dcb23a3239a1e9623b8234222ba7 / app / page / userShow.js

3357 bytesRaw
1const nest = require('depnest')
2const { h, Array: MutantArray, computed, when, map } = require('mutant')
3const pull = require('pull-stream')
4const get = require('lodash/get')
5
6exports.gives = nest('app.page.userShow')
7
8exports.needs = nest({
9 'about.html.image': 'first',
10 'about.obs.name': 'first',
11 'app.html.link': 'first',
12 'app.html.threadCard': 'first',
13 'contact.async.follow': 'first',
14 'contact.async.unfollow': 'first',
15 'contact.obs.followers': 'first',
16 'feed.pull.private': 'first',
17 'feed.pull.rollup': 'first',
18 'keys.sync.id': 'first',
19 'state.obs.threads': 'first',
20 'translations.sync.strings': 'first',
21})
22
23exports.create = (api) => {
24 return nest('app.page.userShow', userShow)
25
26 function userShow (location) {
27
28 const { feed } = location
29 const myId = api.keys.sync.id()
30 const name = api.about.obs.name(feed)
31
32 const strings = api.translations.sync.strings()
33
34 const { followers } = api.contact.obs
35
36 const youFollowThem = computed(followers(feed), followers => followers.has(myId))
37 const theyFollowYou = computed(followers(myId), followers => followers.has(feed))
38 const youAreFriends = computed([youFollowThem, theyFollowYou], (a, b) => a && b)
39
40 const ourRelationship = computed(
41 [youAreFriends, youFollowThem, theyFollowYou],
42 (youAreFriends, youFollowThem, theyFollowYou) => {
43 if (youAreFriends) return strings.userShow.state.friends
44 if (theyFollowYou) return strings.userShow.state.theyFollow
45 if (youFollowThem) return strings.userShow.state.youFollow
46 }
47 )
48 const { unfollow, follow } = api.contact.async
49 const followButton = when(followers(myId).sync,
50 when(youFollowThem,
51 h('Button -subtle', { 'ev-click': () => unfollow(feed) }, strings.userShow.action.unfollow),
52 h('Button -primary', { 'ev-click': () => follow(feed) }, strings.userShow.action.follow)
53 ),
54 h('Button', { disabled: 'disabled' }, strings.loading )
55 )
56
57
58 const threads = MutantArray()
59 pull(
60 // next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']),
61 // api.feed.pull.private({reverse: true, limit: 100, live: false}),
62 api.feed.pull.private({reverse: true, live: false}),
63 pull.filter(msg => {
64 const recps = get(msg, 'value.content.recps')
65 if (!recps) return
66
67 return recps
68 .map(r => typeof r === 'object' ? r.link : r)
69 .includes(feed)
70 }),
71 api.feed.pull.rollup(),
72 pull.drain(threads.push)
73 // Scroller(container, content, render, false, false)
74 )
75
76 const Link = api.app.html.link
77
78 return h('Page -userShow', {title: name}, [
79 h('div.container', [
80 h('header', [
81 h('h1', name),
82 Link({ page: 'userEdit', feed }, h('i.fa.fa-pencil'))
83 ]),
84 api.about.html.image(feed),
85 feed !== myId
86 ? h('div.friendship', [
87 h('div.state', ourRelationship),
88 followButton
89 ]) : '',
90
91
92 // h('div', '...friends in common'),
93 // h('div', '...groups this person is in'),
94
95 feed !== myId
96 ? Link({ page: 'threadNew', feed }, h('Button -primary', strings.userShow.action.directMessage))
97 : '',
98 h('div.threads', map(threads, api.app.html.threadCard))
99 ])
100 ])
101 }
102}
103
104
105

Built with git-ssb-web