git ssb

2+

mixmix / ticktack



Tree: c2bb5938dd867f68b9245abaae29edc60ca2bb7c

Files: c2bb5938dd867f68b9245abaae29edc60ca2bb7c / app / page / userShow.js

3386 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.blogCard': 'first',
13 'contact.async.follow': 'first',
14 'contact.async.unfollow': 'first',
15 'contact.obs.followers': 'first',
16 'sbot.pull.userFeed': 'first',
17 'keys.sync.id': 'first',
18 'translations.sync.strings': 'first',
19})
20
21exports.create = (api) => {
22 return nest('app.page.userShow', userShow)
23
24 function userShow (location) {
25
26 const { feed } = location
27 const myId = api.keys.sync.id()
28 const name = api.about.obs.name(feed)
29
30 const strings = api.translations.sync.strings()
31
32 const { followers } = api.contact.obs
33
34 const youFollowThem = computed(followers(feed), followers => followers.includes(myId))
35 // const theyFollowYou = computed(followers(myId), followers => followers.includes(feed))
36 // const youAreFriends = computed([youFollowThem, theyFollowYou], (a, b) => a && b)
37
38 // const ourRelationship = computed(
39 // [youAreFriends, youFollowThem, theyFollowYou],
40 // (youAreFriends, youFollowThem, theyFollowYou) => {
41 // if (youAreFriends) return strings.userShow.state.friends
42 // if (theyFollowYou) return strings.userShow.state.theyFollow
43 // if (youFollowThem) return strings.userShow.state.youFollow
44 // }
45 // )
46 const { unfollow, follow } = api.contact.async
47 const followButton = when(followers(myId).sync,
48 when(youFollowThem,
49 h('Button -primary', { 'ev-click': () => unfollow(feed) }, strings.userShow.action.unfollow),
50 h('Button -primary', { 'ev-click': () => follow(feed) }, strings.userShow.action.follow)
51 ),
52 h('Button', { disabled: 'disabled' }, strings.loading )
53 )
54
55 const Link = api.app.html.link
56 const userEditButton = Link({ page: 'userEdit', feed }, h('i.fa.fa-pencil'))
57 const directMessageButton = Link({ page: 'threadNew', feed }, h('Button', strings.userShow.action.directMessage))
58
59 const BLOG_TYPES = ['blog', 'post']
60 const blogs = MutantArray()
61 pull(
62 // next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']),
63 // api.feed.pull.private({reverse: true, limit: 100, live: false}),
64 api.sbot.pull.userFeed({id: feed, reverse: true, live: false}),
65 pull.filter(msg => BLOG_TYPES.includes(get(msg, 'value.content.type'))),
66 pull.filter(msg => get(msg, 'value.content.root') === undefined),
67 pull.drain(blogs.push)
68 // Scroller(content, scrollerContent, render, false, false)
69 )
70
71 return h('Page -userShow', {title: name}, [
72 h('div.content', [
73 h('section.about', [
74 api.about.html.image(feed),
75 h('h1', [
76 name,
77 feed === myId // Only expose own profile editing right now
78 ? userEditButton
79 : ''
80 ]),
81 feed !== myId
82 ? h('div.actions', [
83 h('div.friendship', followButton),
84 h('div.directMessage', directMessageButton)
85 ])
86 : '',
87 ]),
88 h('section.blogs', map(blogs, api.app.html.blogCard))
89 ])
90 ])
91 }
92}
93
94
95

Built with git-ssb-web