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