🚧 Avoid duplicated returns
This commit is contained in:
@@ -25,7 +25,6 @@ export default {
|
|||||||
activeCard: '',
|
activeCard: '',
|
||||||
resources: [],
|
resources: [],
|
||||||
searchInput: {},
|
searchInput: {},
|
||||||
tags: [],
|
|
||||||
showTitle: false,
|
showTitle: false,
|
||||||
showCards: false,
|
showCards: false,
|
||||||
}
|
}
|
||||||
@@ -46,13 +45,8 @@ export default {
|
|||||||
this.searchInput = newSearchInput
|
this.searchInput = newSearchInput
|
||||||
},
|
},
|
||||||
searchInput(searchInput) {
|
searchInput(searchInput) {
|
||||||
let resources = []
|
this.resources = this.$store.getters['data/findBySearchInputs'](searchInput.keywords, searchInput.tags)
|
||||||
if (searchInput.keywords)
|
},
|
||||||
resources = resources.concat(this.$store.getters['data/findByName'](searchInput.keywords))
|
|
||||||
if (searchInput.tags)
|
|
||||||
resources = resources.concat(this.$store.getters['data/findByTags'](searchInput.tags))
|
|
||||||
this.resources = resources
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.showTitle = true
|
this.showTitle = true
|
||||||
|
|||||||
@@ -52,6 +52,12 @@ export const getters = {
|
|||||||
|
|
||||||
return getDesiredResources(state.resources)
|
return getDesiredResources(state.resources)
|
||||||
},
|
},
|
||||||
|
findBySearchInputs: (_, getters) => (keywords = [], tags = []) => {
|
||||||
|
const foundByKeywords = getters.findByName(keywords)
|
||||||
|
const foundByTags = getters.findByTags(tags)
|
||||||
|
const uniqueResources = foundByTags.filter(x => !foundByKeywords.some(y => equalResources(x, y)))
|
||||||
|
return uniqueResources.concat(foundByKeywords)
|
||||||
|
},
|
||||||
sortByTitle: (_, getters) => title => {
|
sortByTitle: (_, getters) => title => {
|
||||||
const category = getters.findCategory(title)
|
const category = getters.findCategory(title)
|
||||||
const clone = [...category.resources]
|
const clone = [...category.resources]
|
||||||
@@ -70,4 +76,8 @@ const compareTitles = (x, y) => {
|
|||||||
} else {
|
} else {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const equalResources = (a, b) =>
|
||||||
|
a.title === b.title &&
|
||||||
|
a.cleanTitle == b.cleanTitle
|
||||||
Reference in New Issue
Block a user