Commit 39613c79e32b11885ab4a4e58342b54df3f85b4b
collect search state into struct
mix irving committed on 2/6/2017, 10:06:54 PMParent: 4d12101d5c56d1007d547af47a2cb083913aaf7c
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, computed } = require('@mmckegg/mutant') | ||
3 … | +const { Struct, 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') | |
@@ -87,26 +87,33 @@ | |||
87 | 87 … | var queryStr = path.substr(1).trim() | |
88 | 88 … | var query = queryStr.split(whitespace) | |
89 | 89 … | var matchesQuery = searchFilter(query) | |
90 | 90 … | ||
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], | ||
96 | 102 … | (done, matches) => done && matches === 0) | |
103 … | + | ||
104 … | + | ||
97 | 105 … | const searchHeader = h('Search', [ | |
98 | 106 … | 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']) | ||
103 | 111 … | ]), | |
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 … | + ]) | ||
109 | 116 … | ) | |
110 | 117 … | ]) | |
111 | 118 … | var { container, content } = api.build_scroller({ prepend: searchHeader }) | |
112 | 119 … | container.id = path // helps tabs find this tab | |
@@ -126,19 +133,19 @@ | |||
126 | 133 … | pull( | |
127 | 134 … | u.next(api.sbot_fulltext_search, {query: queryStr, reverse: true, limit: 500, live: false}), | |
128 | 135 … | fallback((err) => { | |
129 | 136 … | if (err === true) { | |
130 | - isFulltextSearchDone.set(true) | ||
137 … | + search.fulltext.isDone.set(true) | ||
131 | 138 … | } else if (/^no source/.test(err.message)) { | |
132 | - isLinearSearch.set(true) | ||
139 … | + search.isLinear.set(true) | ||
133 | 140 … | return pull( | |
134 | 141 … | u.next(api.sbot_log, {reverse: true, limit: 500, live: false}), | |
135 | 142 … | pull.through(() => searched.set(searched()+1)), | |
136 | 143 … | pull.filter(matchesQuery) | |
137 | 144 … | ) | |
138 | 145 … | } | |
139 | 146 … | }), | |
140 | - pull.through(() => matches.set(matches()+1)), | ||
147 … | + pull.through(() => search.matches.set(search.matches()+1)), | ||
141 | 148 … | Scroller(container, content, renderMsg, false, false) | |
142 | 149 … | ) | |
143 | 150 … | ||
144 | 151 … | return container |
Built with git-ssb-web