Files: 2f46470aad18da0d76890f9f0f30c34ada88472b / app / page / threadNew.js
2241 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Struct, Value, Array: MutantArray, computed, map } = require('mutant') |
3 | |
4 | exports.gives = nest('app.page.threadNew') |
5 | |
6 | exports.needs = nest({ |
7 | 'about.html.avatar': 'first', |
8 | 'about.obs.name': 'first', |
9 | 'app.html.sideNav': 'first', |
10 | 'app.html.thread': 'first', |
11 | 'history.sync.push': 'first', |
12 | 'keys.sync.id': 'first', |
13 | 'message.html.compose': 'first', |
14 | 'translations.sync.strings': 'first', |
15 | }) |
16 | |
17 | exports.create = (api) => { |
18 | |
19 | return nest('app.page.threadNew', threadNew) |
20 | |
21 | function threadNew (location) { |
22 | const { feed, channel } = location |
23 | |
24 | if (feed) return threadNewFeed(location) |
25 | } |
26 | |
27 | function threadNewFeed (location) { |
28 | const strings = api.translations.sync.strings() |
29 | const myId = api.keys.sync.id() |
30 | |
31 | const { feed } = location |
32 | const name = api.about.obs.name |
33 | |
34 | const searchInput = Value() |
35 | const meta = Struct({ |
36 | type: 'post', |
37 | recps: MutantArray ([ |
38 | myId, |
39 | { link: feed, name: name(feed) } |
40 | ]), |
41 | subject: Value() |
42 | }) |
43 | |
44 | const composer = api.message.html.compose( |
45 | { meta, shrink: false }, |
46 | (err, msg) => api.history.sync.push(err ? err : Object.assign(msg, { feed })) // TODO check this |
47 | ) |
48 | |
49 | return h('Page -threadNew', {title: strings.threadNew.pageTitle}, [ |
50 | api.app.html.sideNav(location), |
51 | h('div.content', [ |
52 | h('div.container', [ |
53 | h('div.field -to', [ |
54 | h('div.label', strings.threadNew.field.to), |
55 | h('div.recps', [ |
56 | map(meta.recps, Recipient), |
57 | h('input', { |
58 | 'ev-input': e => searchInput.set(e.target.value), |
59 | placeholder: strings.optionalField |
60 | }), |
61 | ]) |
62 | ]), |
63 | h('div.field -subject', [ |
64 | h('div.label', strings.threadNew.field.subject), |
65 | h('input', { |
66 | 'ev-input': e => meta.subject.set(e.target.value), |
67 | placeholder: strings.optionalField |
68 | }), |
69 | ]), |
70 | composer |
71 | ]) |
72 | ]) |
73 | ]) |
74 | |
75 | function Recipient (r) { |
76 | if (r === myId) return |
77 | |
78 | return h('div.recp', [ |
79 | api.about.html.avatar(r.link, 'tiny'), |
80 | h('div.name', r.name) |
81 | ]) |
82 | } |
83 | } |
84 | |
85 | } |
86 | |
87 |
Built with git-ssb-web