git ssb

16+

Dominic / patchbay



Commit 5e5bef4d7a2202ff89f9fd54978ed73376abe898

fix search page and searchBar behaviour

mix irving committed on 8/31/2017, 4:03:47 AM
Parent: dc8089d99ba36f4718ee8f2c3baee8306eb1ccb5

Files changed

app/html/search-bar.jschanged
app/html/tabs.jschanged
app/page/search.jschanged
app/sync/addPage.jschanged
app/sync/catch-keyboard-shortcut.jschanged
router/sync/routes.jschanged
app/html/search-bar.jsView
@@ -15,9 +15,8 @@
1515
1616 return nest('app.html.searchBar', function searchBar () {
1717 if (_search) return _search
1818
19- const goTo = api.app.sync.goTo
2019 const getProfileSuggestions = api.about.async.suggest()
2120 const getChannelSuggestions = api.channel.async.suggest()
2221
2322 const input = h('input', {
@@ -26,9 +25,15 @@
2625 'ev-keyup': ev => {
2726 switch (ev.keyCode) {
2827 case 13: // enter
2928 var location = input.value.trim()
30- if (goTo(location, !ev.ctrlKey)) input.blur()
29+ if (location[0] == '?')
30+ location = { page: 'search', query: location.substring(1) }
31+ else if (!['@', '#', '%', '&'].includes(location[0]))
32+ location = { page: 'search', query: location }
33+
34+ api.app.sync.goTo(location)
35+ if (!ev.ctrlKey) input.blur()
3136 return
3237 case 27: // escape
3338 ev.preventDefault()
3439 input.blur()
app/html/tabs.jsView
@@ -23,16 +23,14 @@
2323 const onSelect = (indexes) => {
2424 const { id } = _tabs.get(indexes[0]).content
2525
2626 try {
27- const location = JSON.parse(id)
28- var locationForSearchBar = Object.keys(location)
29- .map(k => location[k])
30- .join(' + ')
27+ var location = JSON.parse(id)
3128 } catch (e) {
3229 throw new Error('app.html.tabs expects all page ids to be stringified location objects')
3330 }
34- search.input.value = locationForSearchBar
31+
32+ search.input.value = buildSearchBarTermFromLocation(location)
3533 }
3634 _tabs = Tabs(onSelect, {
3735 append: h('div.navExtra', [ search, menu ])
3836 })
@@ -47,4 +45,17 @@
4745 return nest({
4846 'app.html.tabs': tabs
4947 })
5048 }
49+
50+function buildSearchBarTermFromLocation (location) {
51+ if (location.page === 'search')
52+ return '?'+location.query
53+
54+ if (location.page && Object.keys(location).length === 1)
55+ return '/'+location.page
56+
57+ return Object.keys(location)
58+ .map(k => location[k])
59+ .join(', ')
60+}
61+
app/page/search.jsView
@@ -74,13 +74,14 @@
7474
7575 exports.create = function (api) {
7676 return nest('app.page.search', searchPage)
7777
78- function searchPage (path) {
79- var queryStr = path.replace(/^\??/, '').trim()
80- var query = queryStr.split(whitespace)
81- var matchesQuery = searchFilter(query)
78+ function searchPage (location) {
79+ const query = location.query.trim()
8280
81+ var queryTerms = query.split(whitespace)
82+ var matchesQuery = searchFilter(queryTerms)
83+
8384 const search = Struct({
8485 isLinear: Value(false),
8586 linear: Struct({
8687 checked: Value(0)
@@ -93,9 +94,9 @@
9394 const hasNoFulltextMatches = computed([search.fulltext.isDone, search.matches],
9495 (done, matches) => done && matches === 0)
9596
9697 const searchHeader = h('Search', [
97- h('header', h('h1', query.join(' '))),
98+ h('header', h('h1', query)),
9899 when(search.isLinear,
99100 h('section.details', [
100101 h('div.searched', ['Searched: ', search.linear.checked]),
101102 h('div.matches', [search.matches, ' matches'])
@@ -107,13 +108,12 @@
107108 )
108109 ])
109110 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
110111 const { container, content } = api.app.html.scroller({ prepend: [searchHeader, filterMenu] })
111- container.id = path // helps tabs find this tab
112112
113113 function renderMsg (msg) {
114114 var el = api.message.html.render(msg)
115- highlight(el, createOrRegExp(query))
115+ highlight(el, createOrRegExp(queryTerms))
116116 return el
117117 }
118118
119119 function draw () {
@@ -126,9 +126,9 @@
126126 Scroller(container, content, renderMsg, true, false)
127127 )
128128
129129 pull(
130- api.sbot.pull.stream(sbot => next(sbot.fulltext.search, {query: queryStr, reverse: true, limit: 500, live: false})),
130+ api.sbot.pull.stream(sbot => next(sbot.fulltext.search, {query, reverse: true, limit: 500, live: false})),
131131 fallback((err) => {
132132 if (err === true) {
133133 search.fulltext.isDone.set(true)
134134 } else if (/^no source/.test(err.message)) {
@@ -147,8 +147,8 @@
147147 }
148148
149149 draw()
150150
151- container.title = '/search'
151+ container.title = '?'+query
152152 return container
153153 }
154154 }
app/sync/addPage.jsView
@@ -14,15 +14,20 @@
1414 })
1515
1616 // TODO : make it so error catching doesn't need this, move it into goTo
1717 function addPage (location, change, split) {
18- location = api.router.sync.normalise(location)
1918 const tabs = api.app.html.tabs()
20-
2119 const page = api.router.sync.router(location)
2220 if (!page) return
2321
2422 // TODO - review unique page id + naming system
25- page.id = page.id || JSON.stringify(location)
23+ page.id = page.id || buildId(location)
2624 tabs.add(page, change, split)
2725 }
26+
27+ function buildId (location) {
28+ return JSON.stringify(
29+ api.router.sync.normalise(location)
30+ )
31+ }
2832 }
33+
app/sync/catch-keyboard-shortcut.jsView
@@ -75,8 +75,9 @@
7575 var i = sel.reduce(function (a, b) { return Math.min(a, b) })
7676 tabs.remove(sel)
7777 tabs.select(Math.max(i - 1, 0))
7878 }
79+ // TODO add history call in here
7980 return
8081
8182 // Search
8283 case 191: // / = routes search
router/sync/routes.jsView
@@ -9,8 +9,9 @@
99 'public': 'first',
1010 'private': 'first',
1111 'notifications': 'first',
1212 'profile': 'first',
13+ 'search': 'first',
1314 'blob': 'first',
1415 'thread': 'first',
1516 'channel': 'first'
1617 },
@@ -28,10 +29,10 @@
2829 [ loc => loc.page === 'private', pages.private ],
2930 [ loc => loc.page === 'notifications', pages.notifications ],
3031 [ loc => loc.page === 'errors', pages.errors ],
3132 [ loc => loc.page === 'profile', () => pages.profile({ id: myId }) ],
33+ [ loc => loc.page === 'search' && loc.query, pages.search ],
3234
33- // TODO - use is-my-json-valid ?
3435 [ loc => isBlob(loc.blob), pages.blob ],
3536 [ loc => isPresent(loc.channel), pages.channel ],
3637 [ loc => isFeed(loc.feed), pages.profile ],
3738 [ loc => isMsg(loc.key), pages.thread ]

Built with git-ssb-web