diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index de20f0b..2413eeb 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -85,7 +85,7 @@ }" > -
Sorry, no results found for "{{ search }}"
@@ -121,6 +121,7 @@ const { currentRoute, push } = useRouter() const peekData = ref([]) const search = ref("") +const searchResultBlog = ref([]) const loading = ref(false) const filterBy = ref(null) const sortBy = ref(null) @@ -136,6 +137,7 @@ const init = () => { filterBy.value = currentRoute.value.params.filterBy sortBy.value = currentRoute.value.params?.sortBy peekData.value = getPeekData() + searchResultBlog.value = getPeekData() sortPeekData(sortBy.value) loading.value = false homeViewMode.value = Storage.getHomeViewMode() @@ -146,6 +148,7 @@ const loadingImage = getImageUrl("loading") watch(search, () => { if (!search.value) { peekData.value = getPeekData() + searchResultBlog.value = peekData.value } }) @@ -164,34 +167,33 @@ const goToBlogDetail = (item) => { const makeSearch = () => { loading.value = true - const searchResult = [] const searchVal = search.value.toLowerCase() + searchResultBlog.value = [] if (filterBy.value) { peekData.value.forEach(item => { if (filterBy.value === "tag") { if (item.tags && item.tags.join(" ").toLowerCase().includes(searchVal)) { - searchResult.push(item) + searchResultBlog.value.push(item) } } else { if (item.authorName.toLowerCase().includes(searchVal)) { - searchResult.push(item) + searchResultBlog.value.push(item) } } }) } else if (sortBy.value) { peekData.value.forEach(item => { if (item.title.toLowerCase().includes(searchVal)) { - searchResult.push(item) + searchResultBlog.value.push(item) } }) } else { peekData.value.forEach(item => { if (item.title.toLowerCase().includes(searchVal)) { - searchResult.push(item) + searchResultBlog.value.push(item) } }) } - peekData.value = searchResult loading.value = false } @@ -242,11 +244,11 @@ const setFilterKey = (key) => { const sortPeekData = (key) => { if (key === "alpha") { - peekData.value.sort((a, b) => { + searchResultBlog.value.sort((a, b) => { return a["title"].localeCompare(b["title"]) }) } else { - peekData.value.sort((a, b) => { + searchResultBlog.value.sort((a, b) => { return b["createdAt"] - a["createdAt"] }) }