Skip to content

Commit

Permalink
Merge branch 'master' into blog-PR-template
Browse files Browse the repository at this point in the history
  • Loading branch information
koebel authored Jun 3, 2024
2 parents 1c80fae + 0050775 commit d05bdc4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
}"
>
<blog-peek
v-for="(item, index) in peekData"
v-for="(item, index) in searchResultBlog"
:key="index"
:title="item.title"
:created-at="item.createdAt"
Expand All @@ -97,7 +97,7 @@
:banner="item.banner"
@click="goToBlogDetail(item)"
/>
<div v-if="peekData.length === 0"
<div v-if="searchResultBlog.length === 0"
class="home-view--no-results"
>
<div class="message">Sorry, no results found for "{{ search }}"</div>
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -146,6 +148,7 @@ const loadingImage = getImageUrl("loading")
watch(search, () => {
if (!search.value) {
peekData.value = getPeekData()
searchResultBlog.value = peekData.value
}
})
Expand All @@ -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
}
Expand Down Expand Up @@ -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"]
})
}
Expand Down

0 comments on commit d05bdc4

Please sign in to comment.