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