git ssb

2+

mixmix / ticktack



Tree: 5b50cf4764591456ca0e705aba348269bf6c3268

Files: 5b50cf4764591456ca0e705aba348269bf6c3268 / app / page / userShow.js

3337 bytesRaw
1const nest = require('depnest')
2const { h, Array: MutantArray, computed, when, map } = require('mutant')
3const pull = require('pull-stream')
4const get = require('lodash/get')
5const path = require('path')
6
7exports.gives = nest('app.page.userShow')
8
9exports.needs = nest({
10 'about.html.avatar': 'first',
11 'about.obs.name': 'first',
12 'about.obs.description': 'first',
13 'app.html.sideNav': 'first',
14 'app.html.link': 'first',
15 'app.html.blogCard': 'first',
16 'app.html.topNav': 'first',
17 'app.html.scroller': 'first',
18 'contact.html.follow': 'first',
19 'contact.html.block': 'first',
20 'feed.pull.profile': 'first',
21 'feed.pull.rollup': 'first',
22 'message.html.markdown': 'first',
23 'keys.sync.id': 'first',
24 'sbot.pull.userFeed': 'first',
25 'translations.sync.strings': 'first',
26 'unread.sync.isUnread': 'first'
27})
28
29exports.create = (api) => {
30 var isUnread = api.unread.sync.isUnread
31 return nest('app.page.userShow', userShow)
32
33 function userShow (location) {
34 const { feed } = location
35 const myId = api.keys.sync.id()
36
37 const strings = api.translations.sync.strings()
38
39 const Link = api.app.html.link
40 const userEditButton = Link(
41 { page: 'userEdit', feed },
42 // h('i.fa.fa-pencil')
43 h('img', { src: path.join(__dirname, '../../assets', 'edit.png') })
44 )
45 const directMessageButton = Link({ page: 'threadNew', feed }, h('Button', strings.userShow.action.directMessage))
46
47 const BLOG_TYPES = ['blog', 'post']
48
49 // TODO return some of this ?
50 // but maybe this shouldn't be done here ?
51 // pull.through(function (blog) {
52 // if(isUnread(blog))
53 // blog.unread = true
54 // blog.replies.forEach(function (data) { // this was fed rollups
55 // if(isUnread(data))
56 // blog.unread = data.unread = true
57 // })
58 // }),
59
60 const prepend = [
61 api.app.html.topNav(location),
62 h('section.about', [
63 api.about.html.avatar(feed, 'large'),
64 h('h1', [
65 api.about.obs.name(feed),
66 feed === myId // Only expose own profile editing right now
67 ? userEditButton
68 : ''
69 ]),
70 h('div.introduction', computed(api.about.obs.description(feed), d => api.message.html.markdown(d || ''))),
71 feed !== myId
72 ? h('div.actions', [
73 api.contact.html.follow(feed),
74 h('div.directMessage', directMessageButton),
75 api.contact.html.block(feed)
76 ])
77 : '',
78 ]),
79 ]
80
81 const store = MutantArray()
82 // store(console.log)
83
84 return h('Page -userShow', [
85 api.app.html.sideNav(location),
86 api.app.html.scroller({
87 classList: ['content'],
88 prepend,
89 // stream: api.feed.pull.profile(feed),
90 stream: opts => api.sbot.pull.userFeed(Object.assign({}, { id: feed }, opts)),
91 indexProperty: ['value', 'sequence'],
92 filter: () => pull(
93 // pull.filter(msg => get(msg, 'value.author') === feed),
94 pull.filter(msg => typeof msg.value.content !== 'string'),
95 pull.filter(msg => get(msg, 'value.content.root') === undefined),
96 pull.filter(msg => BLOG_TYPES.includes(get(msg, 'value.content.type')))
97 ),
98 render: blog => {
99 return api.app.html.blogCard(blog)
100 },
101 store
102 })
103 ])
104 }
105}
106
107

Built with git-ssb-web