git ssb

2+

mixmix / ticktack



Tree: f1afbfb0382d0d2375a5ca7ec9bc9b673a9bff84

Files: f1afbfb0382d0d2375a5ca7ec9bc9b673a9bff84 / app / page / userShow.js

3451 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(content, scrollerContent, render, false, false)
74 )
75
76 const Link = api.app.html.link
77
78 return h('Page -userShow', {title: name}, [
79 h('div.content', [
80 h('header', [
81 h('h1', name),
82 feed === myId // Only expose own profile editing right now
83 ? Link({ page: 'userEdit', feed }, h('i.fa.fa-pencil'))
84 : ''
85 ]),
86 api.about.html.image(feed),
87 feed !== myId
88 ? h('div.friendship', [
89 h('div.state', ourRelationship),
90 followButton
91 ]) : '',
92
93
94 // h('div', '...friends in common'),
95 // h('div', '...groups this person is in'),
96
97 feed !== myId
98 ? Link({ page: 'threadNew', feed }, h('Button -primary', strings.userShow.action.directMessage))
99 : '',
100 h('div.threads', map(threads, api.app.html.threadCard))
101 ])
102 ])
103 }
104}
105
106
107

Built with git-ssb-web