Commit 56c55873f8f1757cf01207e032a6ff5c4e21439f
Improve channel suggestion
- Complete and open on enter - Reduce and group in query - Highlight active suggestionCharles Lehner committed on 6/28/2016, 3:13:22 PM
Parent: b8bc748408c405a7bd87b57d5b6cf7665b169992
Files changed
modules/search-box.js | changed |
style.css | changed |
modules/search-box.js | ||
---|---|---|
@@ -5,13 +5,18 @@ | ||
5 | 5 | var sbot_query = plugs.first(exports.sbot_query = []) |
6 | 6 | |
7 | 7 | exports.search_box = function (go) { |
8 | 8 | |
9 | + var suggestBox | |
9 | 10 | var search = h('input.searchprompt', { |
10 | 11 | type: 'search', |
11 | 12 | onkeydown: function (ev) { |
12 | 13 | switch (ev.keyCode) { |
13 | 14 | case 13: // enter |
15 | + if (suggestBox && suggestBox.active) { | |
16 | + suggestBox.complete() | |
17 | + ev.stopPropagation() | |
18 | + } | |
14 | 19 | if (go(search.value.trim(), !ev.ctrlKey)) |
15 | 20 | search.blur() |
16 | 21 | return |
17 | 22 | case 27: // escape |
@@ -32,27 +37,25 @@ | ||
32 | 37 | search.value = sigil |
33 | 38 | } |
34 | 39 | } |
35 | 40 | |
36 | - /* | |
37 | - var suggestions = [] | |
38 | - | |
39 | 41 | pull( |
40 | 42 | sbot_query({query: [ |
41 | - {$map: ['value', 'content', 'channel']}, | |
42 | - {$filter: {$prefix: ''}} | |
43 | + {$map: {channel: ['value', 'content', 'channel']}}, | |
44 | + {$reduce: {channel: 'channel', posts: {$count: true}}} | |
43 | 45 | ]}), |
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}) | |
48 | 57 | }) |
49 | 58 | ) |
50 | 59 | |
51 | - // delay until the element has a parent | |
52 | - setTimeout(function () { | |
53 | - suggest(search, {'#': suggestions}) | |
54 | - }, 10) | |
55 | - */ | |
56 | - | |
57 | 60 | return search |
58 | 61 | } |
Built with git-ssb-web