git ssb

16+

Dominic / patchbay



Commit f715d01c1a678fca975815e634302f528078efbf

Show when there are no fulltext search matches

cel committed on 2/6/2017, 4:32:17 PM
Parent: 6b5fd322755eecdeebda31ed6090e626cebdc243

Files changed

modules_extra/search.jschanged
modules_extra/search.jsView
@@ -1,7 +1,7 @@
11 const h = require('../h')
22 const fs = require('fs')
3-const { Value, when } = require('@mmckegg/mutant')
3 +const { Value, when, computed } = require('@mmckegg/mutant')
44 const u = require('../util')
55 const pull = require('pull-stream')
66 const Scroller = require('pull-scroll')
77 const TextNodeSearcher = require('text-node-searcher')
@@ -85,33 +85,33 @@
8585 if (path[0] !== '?') return
8686
8787 var queryStr = path.substr(1).trim()
8888 var query = queryStr.split(whitespace)
89- var _matches = searchFilter(query)
89 + var matchesQuery = searchFilter(query)
9090
9191 const isLinearSearch = Value(false)
92 + const isFulltextSearchDone = Value(false)
9293 const searched = Value(0)
9394 const matches = Value(0)
95 + const hasNoFulltextMatches = computed([isFulltextSearchDone, matches],
96 + (done, matches) => done && matches === 0)
9497 const searchHeader = h('Search', [
9598 h('header', h('h1', query.join(' '))),
9699 when(isLinearSearch,
97100 h('section.details', [
98101 h('div.searched', ['Searched: ', searched]),
99102 h('div.matches', [matches, ' matches'])
100- ])
103 + ]),
104 + when(hasNoFulltextMatches,
105 + h('section.details', [
106 + h('div.matches', 'No matches')
107 + ])
108 + )
101109 )
102110 ])
103111 var { container, content } = api.build_scroller({ prepend: searchHeader })
104112 container.id = path // helps tabs find this tab
105113
106- function matchesQuery (data) {
107- searched.set(searched() + 1)
108- var m = _matches(data)
109- if(m) matches.set(matches() +1 )
110-
111- return m
112- }
113-
114114 function renderMsg(msg) {
115115 var el = api.message_render(msg)
116116 highlight(el, createOrRegExp(query))
117117 return el
@@ -125,16 +125,20 @@
125125
126126 pull(
127127 u.next(api.sbot_fulltext_search, {query: queryStr, reverse: true, limit: 500, live: false}),
128128 fallback((err) => {
129- if (/^no source/.test(err.message)) {
129 + if (err === true) {
130 + isFulltextSearchDone.set(true)
131 + } else if (/^no source/.test(err.message)) {
130132 isLinearSearch.set(true)
131133 return pull(
132134 u.next(api.sbot_log, {reverse: true, limit: 500, live: false}),
135 + pull.through(() => searched.set(searched()+1)),
133136 pull.filter(matchesQuery)
134137 )
135138 }
136139 }),
140 + pull.through(() => matches.set(matches()+1)),
137141 Scroller(container, content, renderMsg, false, false)
138142 )
139143
140144 return container

Built with git-ssb-web