git ssb

2+

mixmix / ticktack



Tree: caccfaabbf34bd8a9c657de74eed2bde040853bd

Files: caccfaabbf34bd8a9c657de74eed2bde040853bd / app / page / threadNew.js

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

Built with git-ssb-web