From 54498ba829c42740994ff8c08290ceee13c543d0 Mon Sep 17 00:00:00 2001 From: Vamshi Reddy Date: Tue, 5 Nov 2024 22:20:24 +0530 Subject: [PATCH 1/2] Added a message to search when no items match --- spin-up-hub/src/components/ContentListing.vue | 81 +++++++++++++------ 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/spin-up-hub/src/components/ContentListing.vue b/spin-up-hub/src/components/ContentListing.vue index 390550c50..1564215b0 100644 --- a/spin-up-hub/src/components/ContentListing.vue +++ b/spin-up-hub/src/components/ContentListing.vue @@ -3,25 +3,30 @@ import Card from "./Card.vue" export default { data() { return { - } - }, + noResultsMessage: '', + isSearching: false, + } + }, components: { Card }, computed: { filteredContentTypes() { return this.$store.state.contentFilters - }, + }, filteredLanguages() { return this.$store.state.languageFilters - }, + }, searchIndex() { return this.$store.state.searchIndex - }, + }, searchTerm() { 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 + '*') @@ -32,38 +37,57 @@ export default { result.map(k => { if (k.score < 5) { return - } + } 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) }) - } - 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) - }) - } + } 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 👀" + } + + return data + } } } - + \ No newline at end of file +