Commit f715d01c1a678fca975815e634302f528078efbf
Show when there are no fulltext search matches
cel committed on 2/6/2017, 4:32:17 PMParent: 6b5fd322755eecdeebda31ed6090e626cebdc243
Files changed
modules_extra/search.js | changed |
modules_extra/search.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 … | const h = require('../h') |
2 | 2 … | const fs = require('fs') |
3 | -const { Value, when } = require('@mmckegg/mutant') | |
3 … | +const { Value, when, computed } = require('@mmckegg/mutant') | |
4 | 4 … | const u = require('../util') |
5 | 5 … | const pull = require('pull-stream') |
6 | 6 … | const Scroller = require('pull-scroll') |
7 | 7 … | const TextNodeSearcher = require('text-node-searcher') |
@@ -85,33 +85,33 @@ | ||
85 | 85 … | if (path[0] !== '?') return |
86 | 86 … | |
87 | 87 … | var queryStr = path.substr(1).trim() |
88 | 88 … | var query = queryStr.split(whitespace) |
89 | - var _matches = searchFilter(query) | |
89 … | + var matchesQuery = searchFilter(query) | |
90 | 90 … | |
91 | 91 … | const isLinearSearch = Value(false) |
92 … | + const isFulltextSearchDone = Value(false) | |
92 | 93 … | const searched = Value(0) |
93 | 94 … | const matches = Value(0) |
95 … | + const hasNoFulltextMatches = computed([isFulltextSearchDone, matches], | |
96 … | + (done, matches) => done && matches === 0) | |
94 | 97 … | const searchHeader = h('Search', [ |
95 | 98 … | h('header', h('h1', query.join(' '))), |
96 | 99 … | when(isLinearSearch, |
97 | 100 … | h('section.details', [ |
98 | 101 … | h('div.searched', ['Searched: ', searched]), |
99 | 102 … | h('div.matches', [matches, ' matches']) |
100 | - ]) | |
103 … | + ]), | |
104 … | + when(hasNoFulltextMatches, | |
105 … | + h('section.details', [ | |
106 … | + h('div.matches', 'No matches') | |
107 … | + ]) | |
108 … | + ) | |
101 | 109 … | ) |
102 | 110 … | ]) |
103 | 111 … | var { container, content } = api.build_scroller({ prepend: searchHeader }) |
104 | 112 … | container.id = path // helps tabs find this tab |
105 | 113 … | |
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 | - | |
114 | 114 … | function renderMsg(msg) { |
115 | 115 … | var el = api.message_render(msg) |
116 | 116 … | highlight(el, createOrRegExp(query)) |
117 | 117 … | return el |
@@ -125,16 +125,20 @@ | ||
125 | 125 … | |
126 | 126 … | pull( |
127 | 127 … | u.next(api.sbot_fulltext_search, {query: queryStr, reverse: true, limit: 500, live: false}), |
128 | 128 … | 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)) { | |
130 | 132 … | isLinearSearch.set(true) |
131 | 133 … | return pull( |
132 | 134 … | u.next(api.sbot_log, {reverse: true, limit: 500, live: false}), |
135 … | + pull.through(() => searched.set(searched()+1)), | |
133 | 136 … | pull.filter(matchesQuery) |
134 | 137 … | ) |
135 | 138 … | } |
136 | 139 … | }), |
140 … | + pull.through(() => matches.set(matches()+1)), | |
137 | 141 … | Scroller(container, content, renderMsg, false, false) |
138 | 142 … | ) |
139 | 143 … | |
140 | 144 … | return container |
Built with git-ssb-web