main-window.jsView |
---|
10 | 10 … | var MutantMap = require('mutant/map') |
11 | 11 … | var Url = require('url') |
12 | 12 … | var insertCss = require('insert-css') |
13 | 13 … | var nest = require('depnest') |
14 | | -var addSuggest = require('suggest-box') |
15 | 14 … | var LatestUpdate = require('./lib/latest-update') |
16 | 15 … | |
17 | 16 … | require('./lib/context-menu-and-spellcheck.js') |
18 | 17 … | |
28 | 27 … | var api = entry(sockets, nest({ |
29 | 28 … | 'page.html.render': 'first', |
30 | 29 … | 'keys.sync.id': 'first', |
31 | 30 … | 'blob.sync.url': 'first', |
32 | | - 'profile.async.suggest': 'first', |
33 | | - 'channel.async.suggest': 'first' |
| 31 … | + 'app.html.search': 'first' |
34 | 32 … | })) |
35 | 33 … | |
36 | 34 … | var renderPage = api.page.html.render |
37 | 35 … | var id = api.keys.sync.id() |
38 | | - var getProfileSuggestions = api.profile.async.suggest() |
39 | | - var getChannelSuggestions = api.channel.async.suggest() |
40 | 36 … | var latestUpdate = LatestUpdate() |
41 | 37 … | |
42 | | - var searchTimer = null |
43 | | - var searchBox = h('input.search', { |
44 | | - type: 'search', |
45 | | - placeholder: 'word, @key, #channel', |
46 | | - 'ev-suggestselect': (ev) => { |
47 | | - setView(ev.detail.id) |
48 | | - searchBox.value = ev.detail.id |
49 | | - } |
50 | | - }) |
51 | | - |
52 | | - searchBox.oninput = function () { |
53 | | - clearTimeout(searchTimer) |
54 | | - searchTimer = setTimeout(doSearch, 500) |
55 | | - } |
56 | | - |
57 | | - searchBox.onfocus = function () { |
58 | | - if (searchBox.value) { |
59 | | - doSearch() |
60 | | - } |
61 | | - } |
62 | | - |
63 | 38 … | var forwardHistory = [] |
64 | 39 … | var backHistory = [] |
65 | 40 … | |
66 | 41 … | var views = MutantDict({ |
119 | 94 … | tab('Public', '/public'), |
120 | 95 … | tab('Private', '/private') |
121 | 96 … | ]), |
122 | 97 … | h('span.appTitle', ['Patchwork']), |
123 | | - h('span', [ searchBox ]), |
| 98 … | + h('span', [ api.app.html.search(setView) ]), |
124 | 99 … | h('span.nav', [ |
125 | 100 … | tab('Profile', id), |
126 | 101 … | tab('Mentions', '/mentions') |
127 | 102 … | ]) |
135 | 110 … | ), |
136 | 111 … | mainElement |
137 | 112 … | ]) |
138 | 113 … | |
139 | | - addSuggest(searchBox, (inputText, cb) => { |
140 | | - if (inputText[0] === '@') { |
141 | | - cb(null, getProfileSuggestions(inputText.slice(1)), {idOnly: true}) |
142 | | - } else if (inputText[0] === '#') { |
143 | | - cb(null, getChannelSuggestions(inputText.slice(1))) |
144 | | - } |
145 | | - }, {cls: 'SuggestBox'}) |
146 | | - |
147 | 114 … | return container |
148 | 115 … | |
149 | 116 … | |
150 | 117 … | |
201 | 168 … | } |
202 | 169 … | |
203 | 170 … | function goBack () { |
204 | 171 … | if (backHistory.length) { |
205 | | - |
206 | 172 … | canGoForward.set(true) |
207 | 173 … | forwardHistory.push(currentView()) |
208 | 174 … | |
209 | 175 … | var view = backHistory.pop() |
252 | 218 … | currentView.set(view) |
253 | 219 … | } |
254 | 220 … | } |
255 | 221 … | |
256 | | - function doSearch () { |
257 | | - var value = searchBox.value.trim() |
258 | | - if (value.startsWith('/') || value.startsWith('?') || value.startsWith('@') || value.startsWith('#') || value.startsWith('%')) { |
259 | | - if (value.startsWith('@') && value.length < 30) { |
260 | | - return |
261 | | - } else if (value.length > 2) { |
262 | | - setView(value) |
263 | | - } |
264 | | - } else if (value.trim()) { |
265 | | - if (value.length > 2) { |
266 | | - setView(`?${value.trim()}`) |
267 | | - } |
268 | | - } else { |
269 | | - setView('/public') |
270 | | - } |
271 | | - } |
272 | | - |
273 | 222 … | function selected (view) { |
274 | 223 … | return computed([currentView, view], (currentView, view) => { |
275 | 224 … | return currentView === view |
276 | 225 … | }) |