Commit cb0a8d89d3cafa851363addec971cc0f0ceb08c8
fix filter to clear userFilter when you wipe that field
mix irving committed on 4/25/2018, 10:01:15 PMParent: 53a8252a78241ac3653bf699e2292ca4a049cc01
Files changed
app/html/filter.js | changed |
app/html/filter.js | ||
---|---|---|
@@ -1,12 +1,13 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | -const { h, Value, when, computed } = require('mutant') | |
2 … | +const { h, Value, when, computed, resolve } = require('mutant') | |
3 | 3 … | const Abort = require('pull-abortable') |
4 | 4 … | const pull = require('pull-stream') |
5 | 5 … | const addSuggest = require('suggest-box') |
6 | -const { isFeed } = require('ssb-ref') | |
7 | 6 … | const get = require('lodash/get') |
8 | 7 … | const isEqual = require('lodash/isEqual') |
8 … | +const isEmpty = require('lodash/isEmpty') | |
9 … | +const { isFeed } = require('ssb-ref') | |
9 | 10 … | |
10 | 11 … | exports.gives = nest('app.html.filter') |
11 | 12 … | |
12 | 13 … | exports.needs = nest({ |
@@ -49,10 +50,23 @@ | ||
49 | 50 … | } |
50 | 51 … | } |
51 | 52 … | }) |
52 | 53 … | |
53 | - const userInput = h('input') | |
54 … | + var userId = Value('') | |
55 … | + userId(id => { | |
56 … | + userInput.value = id | |
57 … | + draw() | |
58 … | + }) | |
59 … | + const userInput = h('input', { | |
60 … | + 'ev-input': (ev) => { | |
61 … | + const { value } = ev.target | |
62 … | + if (value === resolve(userId)) return // stops infinite loop | |
54 | 63 … | |
64 … | + if (isFeed(value)) userId.set(value) | |
65 … | + else if (isEmpty(value)) userId.set('') | |
66 … | + } | |
67 … | + }) | |
68 … | + | |
55 | 69 … | const isFiltered = computed(filterSettings, (filterSettings) => { |
56 | 70 … | const _settings = Object.assign({}, filterSettings) |
57 | 71 … | delete _settings.defaults |
58 | 72 … | |
@@ -140,32 +154,27 @@ | ||
140 | 154 … | |
141 | 155 … | draw() |
142 | 156 … | }) |
143 | 157 … | |
144 | - var userId | |
145 | 158 … | const getAboutSuggestions = api.about.async.suggest() |
146 | 159 … | addSuggest(userInput, (inputText, cb) => { |
147 | 160 … | inputText = inputText.replace(/^@/, '') |
148 | 161 … | cb(null, getAboutSuggestions(inputText.slice(1))) |
149 | 162 … | }, {cls: 'PatchSuggest'}) |
150 | - userInput.addEventListener('suggestselect', ev => { | |
151 | - userId = ev.detail.id | |
152 | - userInput.value = userId | |
163 … | + userInput.addEventListener('suggestselect', ev => userId.set(ev.detail.id)) | |
153 | 164 … | |
154 | - draw() | |
155 | - }) | |
156 | - | |
157 | 165 … | function followFilter (msg) { |
158 | 166 … | if (!filterSettings().only.peopleAndChannelsIFollow) return true |
159 | 167 … | |
160 | 168 … | return Array.from(peopleIFollow()).concat(myId).includes(msg.value.author) || |
161 | 169 … | (msg.value.content && Array.from(channelsIFollow()).includes(msg.value.content.channel)) |
162 | 170 … | } |
163 | 171 … | |
164 | 172 … | function userFilter (msg) { |
165 | - if (!userId) return true | |
173 … | + const id = resolve(userId) | |
174 … | + if (!id) return true | |
166 | 175 … | |
167 | - return msg.value.author === userId | |
176 … | + return msg.value.author === id | |
168 | 177 … | } |
169 | 178 … | |
170 | 179 … | function rootFilter (msg) { |
171 | 180 … | if (!filterSettings().only.rootMessages) return true |
@@ -186,9 +195,9 @@ | ||
186 | 195 … | if (/^chess/.test(type)) { |
187 | 196 … | type = 'chess' |
188 | 197 … | } |
189 | 198 … | |
190 | - if (typeof msg.value.content == 'string') { | |
199 … | + if (typeof msg.value.content === 'string') { | |
191 | 200 … | type = 'private' |
192 | 201 … | } |
193 | 202 … | |
194 | 203 … | return get(filterSettings(), ['show', type], true) |
Built with git-ssb-web