Skip to content

Commit

Permalink
Allow global search for anything
Browse files Browse the repository at this point in the history
Signed-off-by: sagar <sagargurung1001@gmail.com>
  • Loading branch information
SagarGi committed Jun 1, 2024
1 parent 0050775 commit 375d5dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const SORT_OPTIONS = [
]

export const FILTER_OPTIONS = [
{ key: "title", label: "Title" },
{ key: "author", label: "Author" },
{ key: "tag", label: "Tags" }
]
10 changes: 7 additions & 3 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
id="search"
class="home-view--search--input"
v-model="search"
placeholder="Search..."
placeholder="Search anything"
@keyup.enter="makeSearch"
>
<div class="home-view--search--actions">
Expand Down Expand Up @@ -175,10 +175,14 @@ const makeSearch = () => {
if (item.tags && item.tags.join(" ").toLowerCase().includes(searchVal)) {
searchResultBlog.value.push(item)
}
} else {
} else if (filterBy.value === "author") {
if (item.authorName.toLowerCase().includes(searchVal)) {
searchResultBlog.value.push(item)
}
} else {
if (item.title.toLowerCase().includes(searchVal)) {
searchResultBlog.value.push(item)
}
}
})
} else if (sortBy.value) {
Expand All @@ -189,7 +193,7 @@ const makeSearch = () => {
})
} else {
peekData.value.forEach(item => {
if (item.title.toLowerCase().includes(searchVal)) {
if ((item.tags && item.tags.join(" ").toLowerCase().includes(searchVal)) || (item.authorName.toLowerCase().includes(searchVal)) || (item.title.toLowerCase().includes(searchVal))) {
searchResultBlog.value.push(item)
}
})
Expand Down

0 comments on commit 375d5dc

Please sign in to comment.