git ssb

16+

Dominic / patchbay



Commit 56c55873f8f1757cf01207e032a6ff5c4e21439f

Improve channel suggestion

- Complete and open on enter
- Reduce and group in query
- Highlight active suggestion
Charles Lehner committed on 6/28/2016, 3:13:22 PM
Parent: b8bc748408c405a7bd87b57d5b6cf7665b169992

Files changed

modules/search-box.jschanged
style.csschanged
modules/search-box.jsView
@@ -5,13 +5,18 @@
55 var sbot_query = plugs.first(exports.sbot_query = [])
66
77 exports.search_box = function (go) {
88
9+ var suggestBox
910 var search = h('input.searchprompt', {
1011 type: 'search',
1112 onkeydown: function (ev) {
1213 switch (ev.keyCode) {
1314 case 13: // enter
15+ if (suggestBox && suggestBox.active) {
16+ suggestBox.complete()
17+ ev.stopPropagation()
18+ }
1419 if (go(search.value.trim(), !ev.ctrlKey))
1520 search.blur()
1621 return
1722 case 27: // escape
@@ -32,27 +37,25 @@
3237 search.value = sigil
3338 }
3439 }
3540
36- /*
37- var suggestions = []
38-
3941 pull(
4042 sbot_query({query: [
41- {$map: ['value', 'content', 'channel']},
42- {$filter: {$prefix: ''}}
43+ {$map: {channel: ['value', 'content', 'channel']}},
44+ {$reduce: {channel: 'channel', posts: {$count: true}}}
4345 ]}),
44- pull.unique(),
45- pull.drain(function (chan) {
46- console.log('chan', chan)
47- suggestions.push({title: '#'+chan, value: '#'+chan})
46+ pull.collect(function (err, chans) {
47+ if (err) return console.error(err)
48+ var suggestions = chans.map(function (chan) {
49+ var name = '#' + chan.channel
50+ if (name) return {
51+ title: name,
52+ value: name,
53+ subtitle: chan.posts
54+ }
55+ }).filter(Boolean)
56+ suggestBox = suggest(search, {'#': suggestions})
4857 })
4958 )
5059
51- // delay until the element has a parent
52- setTimeout(function () {
53- suggest(search, {'#': suggestions})
54- }, 10)
55- */
56-
5760 return search
5861 }
style.cssView
@@ -132,8 +132,12 @@
132132 // flex-direction: row;
133133 width: 200px;
134134 }
135135
136+.suggest-box .selected {
137+ background: yellow;
138+}
139+
136140 .suggest-box img {
137141 width: 50px;
138142 }
139143 .suggest-box,.selected img {

Built with git-ssb-web