Skip to content

Commit

Permalink
Enhance search for sorting and filters
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 b52e37d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 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" }
]
7 changes: 5 additions & 2 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="searchByPlaceHolder"
@keyup.enter="makeSearch"
>
<div class="home-view--search--actions">
Expand Down Expand Up @@ -124,6 +124,7 @@ const search = ref("")
const searchResultBlog = ref([])
const loading = ref(false)
const filterBy = ref(null)
const searchByPlaceHolder = ref("Search By title")
const sortBy = ref(null)
const homeViewMode = ref(null)
Expand All @@ -134,7 +135,7 @@ onMounted(async () => {
const init = () => {
loading.value = true
filterBy.value = currentRoute.value.params.filterBy
filterBy.value = currentRoute.value.params?.filterBy
sortBy.value = currentRoute.value.params?.sortBy
peekData.value = getPeekData()
searchResultBlog.value = getPeekData()
Expand Down Expand Up @@ -207,6 +208,7 @@ const toHome = () => {
peekData.value = getPeekData()
sortPeekData(sortBy.value)
search.value = ""
searchByPlaceHolder.value = "Search by title"
})
}
Expand All @@ -231,6 +233,7 @@ const setFilterKey = (key) => {
if (currentRoute.value.params.filterBy === key) {
toHome()
} else {
searchByPlaceHolder.value = "Search By " + key
push({
name: "Filter",
params: {
Expand Down

0 comments on commit b52e37d

Please sign in to comment.