git ssb

16+

Dominic / patchbay



Commit 302ee34806865960fcbafa16cb1419c070150269

Add support for a channel input box

Bradley Donahue committed on 2/3/2017, 7:26:16 PM
Parent: e50286f70acfd2b61a42f560edfdfc1083b1e0fc

Files changed

modules_basic/compose.jschanged
modules_basic/compose.mcsschanged
modules_extra/channel.jschanged
modules_basic/compose.jsView
@@ -4,8 +4,9 @@
44 const mentions = require('ssb-mentions')
55
66 exports.needs = {
77 suggest_mentions: 'map', //<-- THIS MUST BE REWRITTEN
8 + suggest_channel: 'map',
89 build_suggest_box: 'first',
910 publish: 'first',
1011 message_content: 'first',
1112 message_confirm: 'first',
@@ -46,8 +47,13 @@
4647 var textArea = h('textarea', {
4748 placeholder: opts.placeholder || 'Write a message'
4849 })
4950
51 + var channelInput = h('input.channel', {
52 + placeholder: '#channel',
53 + value: meta.channel || ''
54 + })
55 +
5056 if(opts.shrink !== false) {
5157 var blur
5258 textArea.addEventListener('focus', () => {
5359 clearTimeout(blur)
@@ -79,8 +85,10 @@
7985 try {
8086 content = JSON.parse(textArea.value)
8187 } catch (err) {
8288 meta.text = textArea.value
89 + meta.channel = (channelInput.value.startsWith('#') ?
90 + channelInput.value.substr(1).trim() : channelInput.value.trim()) || null
8391 meta.mentions = mentions(textArea.value).map(mention => {
8492 // merge markdown-detected mention with file info
8593 var file = filesById[mention.link]
8694 if (file) {
@@ -125,13 +133,15 @@
125133 fileInput, publishBtn
126134 ])
127135
128136 api.build_suggest_box(textArea, api.suggest_mentions)
137 + api.build_suggest_box(channelInput, api.suggest_channel)
129138
130139 var composer = h('Compose', {
131140 className: opts.shrink === false ? '-expanded' : '-contracted'
132141 }, [
133142 textArea,
143 + channelInput,
134144 actions
135145 ])
136146
137147
modules_basic/compose.mcssView
@@ -7,8 +7,13 @@
77 textarea {
88 border: 1px solid gainsboro
99 }
1010
11 + input.channel {
12 + border: 1px solid gainsboro
13 + padding: .5rem
14 + }
15 +
1116 section.actions {
1217 display: flex
1318 flex-direction: row
1419 align-items: baseline
@@ -25,9 +30,9 @@
2530
2631 ::-webkit-file-upload-button {
2732 visibility: hidden
2833 }
29-
34 +
3035 ::before {
3136 $composeButton
3237 padding-top: .3rem
3338
@@ -37,12 +42,12 @@
3742 outline: none
3843 white-space: nowrap
3944 -webkit-user-select: none
4045 }
41-
46 +
4247 :active, :focus {
4348 outline: none
44- box-shadow: none
49 + box-shadow: none
4550 }
4651 }
4752
4853 button {
@@ -59,19 +64,27 @@
5964 height: 200px
6065 transition: height .15s ease-out
6166 }
6267
68 + input.channel {
69 + display: flex
70 + }
71 +
6372 section.actions {
6473 display: flex
6574 }
6675 }
6776
68- -contracted {
77 + -contracted {
6978 textarea {
7079 height: 50px
7180 transition: height .15s ease-in
7281 }
7382
83 + input.channel {
84 + display: none
85 + }
86 +
7487 section.actions {
7588 display: none
7689 }
7790 }
@@ -86,5 +99,4 @@
8699 padding: .5rem
87100 margin: 0
88101 cursor: pointer
89102 }
90-
modules_extra/channel.jsView
@@ -15,9 +15,10 @@
1515 message_meta: true,
1616 screen_view: true,
1717 connection_status: true,
1818 suggest_search: true,
19- suggest_mentions: true
19 + suggest_mentions: true,
20 + suggest_channel: true
2021 }
2122
2223 exports.create = function (api) {
2324
@@ -34,9 +35,10 @@
3435 message_meta,
3536 screen_view,
3637 connection_status,
3738 suggest_search,
38- suggest_mentions
39 + suggest_mentions,
40 + suggest_channel
3941 }
4042
4143 function message_meta (msg) {
4244 var chan = msg.value.content.channel
@@ -135,6 +137,23 @@
135137 }
136138 }))
137139 }
138140 }
141 +
142 + function suggest_channel (query) {
143 + return function (cb) {
144 + if (!/^#\w/.test(query)) return cb()
145 +
146 + cb(null, channels.filter(function (chan) {
147 + return (`#${chan.name}`).substring(0, query.length) === query
148 + })
149 + .map(function (chan) {
150 + var name = `#${chan.name}`
151 + return {
152 + title: name,
153 + subtitle: `(${chan.rank})`,
154 + value: name.substr(1)
155 + }
156 + }))
157 + }
158 + }
139159 }
140-

Built with git-ssb-web