git ssb

2+

mixmix / ticktack



Tree: 52acefb26cfdc545a5bef98c649d3cfbec4ac257

Files: 52acefb26cfdc545a5bef98c649d3cfbec4ac257 / app / page / blogNew.js

2388 bytesRaw
1const nest = require('depnest')
2const { h, Struct, Value } = require('mutant')
3const addSuggest = require('suggest-box')
4
5exports.gives = nest('app.page.blogNew')
6
7exports.needs = nest({
8 'app.html.context': 'first',
9 'channel.async.suggest': 'first',
10 'history.sync.push': 'first',
11 'message.html.compose': 'first',
12 'translations.sync.strings': 'first',
13})
14
15exports.create = (api) => {
16 var contentHtmlObs
17
18 return nest('app.page.blogNew', blogNew)
19
20 function blogNew (location) {
21 const strings = api.translations.sync.strings()
22 const getChannelSuggestions = api.channel.async.suggest()
23
24 const meta = Struct({
25 type: 'blog',
26 channel: Value(),
27 title: Value(),
28 })
29
30 const composer = api.message.html.compose(
31 { meta, shrink: false },
32 (err, msg) => api.history.sync.push(err ? err : msg)
33 )
34
35 const channelInput = h('input', {
36 'ev-input': e => meta.channel.set(e.target.value),
37 placeholder: strings.channel
38 })
39 var page = h('Page -blogNew', [
40 api.app.html.context(location),
41 h('div.content', [
42 h('div.field -channel', [
43 h('div.label', strings.channel),
44 channelInput
45 ]),
46 h('div.field -title', [
47 h('div.label', strings.blogNew.field.title),
48 h('input', {
49 'ev-input': e => meta.title.set(e.target.value),
50 placeholder: strings.blogNew.field.title
51 }),
52 ]),
53 composer
54 ])
55 ])
56
57 addSuggest(channelInput, (inputText, cb) => {
58 var suggestions = getChannelSuggestions(inputText)
59 .map(s => {
60 s.value = s.value.replace(/^#/, '') // strip the defualt # prefix here
61 return s
62 })
63 .map(s => {
64 if (s.subtitle === 'subscribed')
65 s.subtitle = h('i.fa.fa-heart') // TODO - translation-friendly subscribed
66 return s
67 })
68
69 // HACK add the input text if it's not an option already
70 if (!suggestions.some(s => s.title === inputText)) {
71 suggestions.push({
72 title: inputText,
73 subtitle: h('i.fa.fa-plus-circle'),
74 value: inputText
75 })
76 }
77
78 cb(null, suggestions)
79 }, {cls: 'PatchSuggest.-channelHorizontal'}) // WARNING hacking suggest-box cls
80
81 channelInput.addEventListener('suggestselect', (e) => channel.set(e.value))
82
83 return page
84 }
85}
86

Built with git-ssb-web