Skip to content

Commit

Permalink
feat: improve negative tags functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Sep 4, 2020
1 parent fdeed26 commit 558099f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
28 changes: 18 additions & 10 deletions components/pages/posts/navigation/search/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
/>
</button>

<!-- Filter content -->
<!-- Negative -->
<button
type="button"
title="Filter out content"
@click="toggleBlacklistFilter()"
@click="toggleNegativeTags()"
>
<FilterIcon
:class="{ 'text-red-400': search.blacklistFilter.isActive }"
:class="{ 'text-red-400': isNegativeTagsActive }"
class="w-6 h-6 transition-colors duration-300 icon"
/>
</button>
Expand All @@ -53,8 +53,8 @@
</template>

<script>
import { mapState, mapActions, mapMutations } from 'vuex'
import { FilterIcon, SearchIcon, TrashIcon } from 'vue-feather-icons'
import { mapGetters, mapActions } from 'vuex'
import { TagIcon, SearchIcon, FilterIcon, TrashIcon } from 'vue-feather-icons'
import debounce from 'lodash/debounce'
export default {
Expand All @@ -69,7 +69,10 @@ export default {
},
computed: {
...mapState('booru', ['search']),
...mapGetters('navigation', [
'isNegativeTagsActive',
]),
...mapGetters('premium', ['isUserPremium']),
},
methods: {
Expand All @@ -78,10 +81,13 @@ export default {
'searchedTagsManager',
'fetchSearchTag',
]),
...mapMutations('booru', ['setBlacklistFilterActive']),
...mapActions('navigation', [
'negativeTagsManager',
]),
replaceInput(event) {
this.searchQuery = event.target.value.replace(/\s+/g, '_').toLowerCase()
this.searchQuery = event.target.value.replace(/\s+/g, '_')
event.target.value = this.searchQuery
this.getTags()
Expand All @@ -108,8 +114,10 @@ export default {
this.addedTagsManager({ operation: 'reset' })
},
toggleBlacklistFilter() {
this.setBlacklistFilterActive(!this.search.blacklistFilter.isActive)
toggleNegativeTags() {
this.negativeTagsManager({ operation: 'toggle' })
},
},
},
}
Expand Down
19 changes: 6 additions & 13 deletions components/pages/posts/navigation/search/SearchResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,12 @@ export default {
},
addToAddedTags(tag) {
if (this.search.blacklistFilter.isActive) {
this.addedTagsManager({
operation: 'add',
value: '-' + tag,
})
}
//
else {
this.addedTagsManager({
operation: 'add',
value: tag,
})
}
const prefix = this.isNegativeTagsActive ? '-' : ''
this.addedTagsManager({
operation: 'add',
value: prefix + tag,
})
},
fetchAddedTags() {
Expand Down
6 changes: 0 additions & 6 deletions store/booru/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export const state = () => ({
search: {
addedTags: [],
searchedTags: [],

blacklistFilter: { isActive: false },
},
})

Expand Down Expand Up @@ -101,10 +99,6 @@ export const mutations = {
setSearchedTags(state, value) {
state.search.searchedTags = value
},

setBlacklistFilterActive(state, value) {
state.search.blacklistFilter.isActive = value
},
}

export const actions = {
Expand Down
26 changes: 26 additions & 0 deletions store/navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const state = () => ({

search: {
isActive: false,

negativeTags: { isActive: false },
},
})

Expand All @@ -17,6 +19,10 @@ export const getters = {
return state.search.isActive
},

isNegativeTagsActive(state) {
return state.search.negativeTags.isActive
},

}

export const mutations = {
Expand All @@ -27,6 +33,11 @@ export const mutations = {
setSearchIsActive(state, value) {
state.search.isActive = value
},

setSearchNegativeTagsIsActive(state, value) {
state.search.negativeTags.isActive = value
},

export const actions = {
sideNavNavigationManager({ commit, getters }, { operation, value }) {
switch (operation) {
Expand Down Expand Up @@ -58,4 +69,19 @@ export const actions = {
}
},

negativeTagsManager({ commit, getters }, { operation, value }) {
switch (operation) {
case 'toggle':
commit('setSearchNegativeTagsIsActive', !getters.isNegativeTagsActive)
break

case 'set':
commit('setSearchNegativeTagsIsActive', value)
break

default:
throw new Error('No operation specified')
}
},

}

0 comments on commit 558099f

Please sign in to comment.