git ssb

16+

Dominic / patchbay



Commit cb0a8d89d3cafa851363addec971cc0f0ceb08c8

fix filter to clear userFilter when you wipe that field

mix irving committed on 4/25/2018, 10:01:15 PM
Parent: 53a8252a78241ac3653bf699e2292ca4a049cc01

Files changed

app/html/filter.jschanged
app/html/filter.jsView
@@ -1,12 +1,13 @@
11 const nest = require('depnest')
2-const { h, Value, when, computed } = require('mutant')
2 +const { h, Value, when, computed, resolve } = require('mutant')
33 const Abort = require('pull-abortable')
44 const pull = require('pull-stream')
55 const addSuggest = require('suggest-box')
6-const { isFeed } = require('ssb-ref')
76 const get = require('lodash/get')
87 const isEqual = require('lodash/isEqual')
8 +const isEmpty = require('lodash/isEmpty')
9 +const { isFeed } = require('ssb-ref')
910
1011 exports.gives = nest('app.html.filter')
1112
1213 exports.needs = nest({
@@ -49,10 +50,23 @@
4950 }
5051 }
5152 })
5253
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
5463
64 + if (isFeed(value)) userId.set(value)
65 + else if (isEmpty(value)) userId.set('')
66 + }
67 + })
68 +
5569 const isFiltered = computed(filterSettings, (filterSettings) => {
5670 const _settings = Object.assign({}, filterSettings)
5771 delete _settings.defaults
5872
@@ -140,32 +154,27 @@
140154
141155 draw()
142156 })
143157
144- var userId
145158 const getAboutSuggestions = api.about.async.suggest()
146159 addSuggest(userInput, (inputText, cb) => {
147160 inputText = inputText.replace(/^@/, '')
148161 cb(null, getAboutSuggestions(inputText.slice(1)))
149162 }, {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))
153164
154- draw()
155- })
156-
157165 function followFilter (msg) {
158166 if (!filterSettings().only.peopleAndChannelsIFollow) return true
159167
160168 return Array.from(peopleIFollow()).concat(myId).includes(msg.value.author) ||
161169 (msg.value.content && Array.from(channelsIFollow()).includes(msg.value.content.channel))
162170 }
163171
164172 function userFilter (msg) {
165- if (!userId) return true
173 + const id = resolve(userId)
174 + if (!id) return true
166175
167- return msg.value.author === userId
176 + return msg.value.author === id
168177 }
169178
170179 function rootFilter (msg) {
171180 if (!filterSettings().only.rootMessages) return true
@@ -186,9 +195,9 @@
186195 if (/^chess/.test(type)) {
187196 type = 'chess'
188197 }
189198
190- if (typeof msg.value.content == 'string') {
199 + if (typeof msg.value.content === 'string') {
191200 type = 'private'
192201 }
193202
194203 return get(filterSettings(), ['show', type], true)

Built with git-ssb-web