Skip to content

Commit

Permalink
fix: support filtering on tags containing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
smeijer committed Jul 4, 2021
1 parent ea73355 commit 681ccda
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/routes/blog/index.tsx
Expand Up @@ -118,13 +118,15 @@ function BlogHome() {

function toggleTag(tag: string) {
setQuery(q => {
const newQuery = q.includes(tag)
? q
.split(' ')
.filter(s => s !== tag)
.join(' ')
// create a regexp so that we can replace multiple occurrences (`react node react`)
const expression = new RegExp(tag, 'ig')

const newQuery = expression.test(q)
? q.replace(expression, '')
: `${q} ${tag}`
return newQuery.trim()

// trim and remove subsequent spaces (`react node ` => `react node`)
return newQuery.replace(/\s+/g, ' ').trim()
})
}

Expand Down

0 comments on commit 681ccda

Please sign in to comment.