git ssb

16+

Dominic / patchbay



Commit 39613c79e32b11885ab4a4e58342b54df3f85b4b

collect search state into struct

mix irving committed on 2/6/2017, 10:06:54 PM
Parent: 4d12101d5c56d1007d547af47a2cb083913aaf7c

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, computed } = require('@mmckegg/mutant')
3 +const { Struct, 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')
@@ -87,26 +87,33 @@
8787 var queryStr = path.substr(1).trim()
8888 var query = queryStr.split(whitespace)
8989 var matchesQuery = searchFilter(query)
9090
91- const isLinearSearch = Value(false)
92- const isFulltextSearchDone = Value(false)
93- const searched = Value(0)
94- const matches = Value(0)
95- const hasNoFulltextMatches = computed([isFulltextSearchDone, matches],
91 + const search = Struct({
92 + isLinear: Value(false),
93 + linear: Struct({
94 + checked: Value(0)
95 + }),
96 + fulltext: Struct({
97 + isDone: Value(false)
98 + }),
99 + matches: Value(0)
100 + })
101 + const hasNoFulltextMatches = computed([search.fulltext.isDone, search.matches],
96102 (done, matches) => done && matches === 0)
103 +
104 +
97105 const searchHeader = h('Search', [
98106 h('header', h('h1', query.join(' '))),
99- when(isLinearSearch,
100- h('section.details', [
101- h('div.searched', ['Searched: ', searched]),
102- h('div.matches', [matches, ' matches'])
107 + when(search.isLinear,
108 + h('section.details', [
109 + h('div.searched', ['Searched: ', search.linear.checked]),
110 + h('div.matches', [search.matches, ' matches'])
103111 ]),
104- when(hasNoFulltextMatches,
105- h('section.details', [
106- h('div.matches', 'No matches')
107- ])
108- )
112 + h('section.details', [
113 + h('div.searched'),
114 + when(hasNoFulltextMatches, h('div.matches', 'No matches'))
115 + ])
109116 )
110117 ])
111118 var { container, content } = api.build_scroller({ prepend: searchHeader })
112119 container.id = path // helps tabs find this tab
@@ -126,19 +133,19 @@
126133 pull(
127134 u.next(api.sbot_fulltext_search, {query: queryStr, reverse: true, limit: 500, live: false}),
128135 fallback((err) => {
129136 if (err === true) {
130- isFulltextSearchDone.set(true)
137 + search.fulltext.isDone.set(true)
131138 } else if (/^no source/.test(err.message)) {
132- isLinearSearch.set(true)
139 + search.isLinear.set(true)
133140 return pull(
134141 u.next(api.sbot_log, {reverse: true, limit: 500, live: false}),
135142 pull.through(() => searched.set(searched()+1)),
136143 pull.filter(matchesQuery)
137144 )
138145 }
139146 }),
140- pull.through(() => matches.set(matches()+1)),
147 + pull.through(() => search.matches.set(search.matches()+1)),
141148 Scroller(container, content, renderMsg, false, false)
142149 )
143150
144151 return container

Built with git-ssb-web