Files: 9b70108d00646124112662ec83dd9733d7afca7d / app / page / threadNew.js
3034 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Struct, Value, computed } = require('mutant') |
3 | |
4 | exports.gives = nest('app.page.threadNew') |
5 | |
6 | exports.needs = nest({ |
7 | 'about.html.image': 'first', |
8 | 'about.obs.name': 'first', |
9 | 'app.html.context': '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 | // if (channel) return threadNewChannel(location) |
26 | } |
27 | |
28 | function threadNewFeed (location) { |
29 | const strings = api.translations.sync.strings() |
30 | |
31 | const { feed } = location |
32 | const name = api.about.obs.name(feed) |
33 | |
34 | const meta = Struct({ |
35 | type: 'post', |
36 | recps: [ |
37 | api.keys.sync.id(), |
38 | { link: feed, name } |
39 | ], |
40 | subject: Value() |
41 | }) |
42 | const composer = api.message.html.compose( |
43 | { meta, shrink: false }, |
44 | (err, msg) => api.history.sync.push(err ? err : Object.assign(msg, { feed })) |
45 | ) |
46 | |
47 | return h('Page -threadNew', {title: strings.threadNew.pageTitle}, [ |
48 | api.app.html.context(location), |
49 | h('div.content', [ |
50 | h('div.container', [ |
51 | h('div.field -to', [ |
52 | h('div.label', strings.threadNew.field.to), |
53 | h('div.recps', [ |
54 | h('div.recp', [ |
55 | api.about.html.image(feed), |
56 | h('div.name', name) |
57 | ]) |
58 | ]) |
59 | ]), |
60 | h('div.field -subject', [ |
61 | h('div.label', strings.threadNew.field.subject), |
62 | h('input', { |
63 | 'ev-input': e => meta.subject.set(e.target.value), |
64 | placeholder: strings.optionalField |
65 | }), |
66 | ]), |
67 | composer |
68 | ]) |
69 | ]) |
70 | ]) |
71 | } |
72 | |
73 | // function threadNewChannel (location) { |
74 | // const strings = api.translations.sync.strings() |
75 | |
76 | // const { channel, flash } = location |
77 | |
78 | // const meta = Struct({ |
79 | // type: 'post', |
80 | // channel, |
81 | // subject: Value() |
82 | // }) |
83 | // const composer = api.message.html.compose( |
84 | // { meta, shrink: false }, |
85 | // (err, msg) => api.history.sync.push(err ? err : msg) |
86 | // ) |
87 | |
88 | // return h('Page -threadNew', {title: strings.threadNew.pageTitle}, [ |
89 | // h('div.content', [ |
90 | // flash ? h('div.flash', flash) : '', |
91 | // h('div.field -channel', [ |
92 | // h('div.label', strings.channel), |
93 | // h('div.recps', [ |
94 | // h('div.recp', [ |
95 | // h('div.name', `#${channel}`) |
96 | // ]) |
97 | // ]) |
98 | // ]), |
99 | // h('div.field -subject', [ |
100 | // h('div.label', strings.threadNew.field.subject), |
101 | // h('input', { |
102 | // 'ev-input': e => meta.subject.set(e.target.value), |
103 | // placeholder: strings.optionalField |
104 | // }), |
105 | // ]), |
106 | // composer |
107 | // ]) |
108 | // ]) |
109 | // } |
110 | } |
111 | |
112 |
Built with git-ssb-web