diff --git a/spin-up-hub/src/components/ContentListing.vue b/spin-up-hub/src/components/ContentListing.vue index 390550c50..fbba9a6f4 100644 --- a/spin-up-hub/src/components/ContentListing.vue +++ b/spin-up-hub/src/components/ContentListing.vue @@ -3,6 +3,8 @@ import Card from "./Card.vue" export default { data() { return { + noResultsMessage: '', + isSearching: false, } }, components: { Card }, @@ -20,8 +22,11 @@ export default { return this.$store.state.searchTerm }, contentItems() { - let data = this.$store.state.contentItems + let data = this.$store.state.contentItems || [] + this.noResultsMessage = '' + if (this.searchTerm) { + this.isSearching = true; let updatedQuery = this.searchTerm .split(" ") .map(word => word + '^2 ' + word + '*') @@ -36,34 +41,53 @@ export default { matches.push(data.find(docs => k.ref == docs.id)) }) data = matches + } else { + this.isSearching = false; + if (data.length === 0) { + this.noResultsMessage = "No items available." + } } + let contentFilterLength = this.filteredContentTypes.length - let langaugeFilterLength = this.filteredLanguages.length - if (contentFilterLength + langaugeFilterLength === 0) { return data } + let languageFilterLength = this.filteredLanguages.length + + if (contentFilterLength + languageFilterLength === 0) { + if (data.length === 0 && this.isSearching) { + this.noResultsMessage = "No items matched your search." + } + return data; + } + if (contentFilterLength === 0) { return data.filter(k => { return this.filteredLanguages.includes(k.language) }) } if (langaugeFilterLength === 0) { return data.filter(k => { return this.filteredContentTypes.includes(k.category) }) + } else { + data = data.filter(k => + this.filteredContentTypes.includes(k.category) && + this.filteredLanguages.includes(k.language) + ) + } + + if (data.length === 0 && this.isSearching) { + this.noResultsMessage = "No items matched your search 👀" } - console.log(data.filter(k => { - return this.filteredContentTypes.includes(k.category) && this.filteredLanguages.includes(k.language) - })) - return data.filter(k => { - return this.filteredContentTypes.includes(k.category) && this.filteredLanguages.includes(k.language) - }) + + return data } } } - + \ No newline at end of file