Skip to content

Commit

Permalink
Added pills for subcategories in search
Browse files Browse the repository at this point in the history
  • Loading branch information
MRVDH committed Feb 19, 2021
1 parent 7c3845e commit 28a3199
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
7 changes: 6 additions & 1 deletion client/src/components/others/CategoryAndProducts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<div>
<b-row v-if="showHeader">
<b-col cols="12">
<span class="category-name">{{ category.name }}</span>
<span
:id="category.id"
class="category-name"
>
{{ category.name }}
</span>
</b-col>
</b-row>
<b-row>
Expand Down
64 changes: 62 additions & 2 deletions client/src/components/routes/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
@click="goBack()"
/>
{{ selectedSubCategory ? selectedSubCategory.name : selectedTopCategory.name }}

<b-tabs
v-if="selectedSubCategory && finalCategories.length !== 1"
v-model="subCategoryTabIndex"
pills
>
<b-tab
v-for="item in subListCategories"
:key="item.id"
:title="item.name"
@click="jumpToCategory(item.id)"
/>
</b-tabs>
</div>
</b-list-group-item>

Expand All @@ -28,7 +41,7 @@
class="other-items"
>
<b-list-group-item
v-for="n in 8"
v-for="n in 19"
:key="n"
>
<b-skeleton-img no-aspect />
Expand Down Expand Up @@ -115,6 +128,7 @@
v-for="category in finalCategories"
:key="category.id"
:category="category"
:show-header="finalCategories.length !== 1"
/>
</div>
</div>
Expand All @@ -138,12 +152,16 @@ export default {
selectedSubCategory: null,
finalCategories: [],
suggestions: [],
searchResults: []
searchResults: [],
subCategoryTabIndex: 0
}
},
computed: {
loggedIn () {
return this.$store.state.authKey;
},
subListCategories () {
return this.selectedSubCategory && this.selectedSubCategory.items && this.selectedSubCategory.items.length ? this.selectedSubCategory.items.filter(x => x.type === "CATEGORY") : [];
}
},
watch: {
Expand All @@ -167,13 +185,19 @@ export default {
});
}
},
created () {
window.addEventListener('scroll', this.handleScroll);
},
mounted () {
if (this.$route.params.query) {
this.selectSuggestion(this.$route.params.query);
}
this.getCategories();
},
destroyed () {
window.removeEventListener('scroll', this.handleScroll);
},
methods: {
getCategories () {
ApiService.getCategories().then(res => {
Expand Down Expand Up @@ -227,12 +251,48 @@ export default {
this.selectedTopCategory = null;
this.$router.push({ name: 'Search' });
}
},
jumpToCategory (id) {
window.scrollTo({top: document.getElementById(id).getBoundingClientRect().top + window.pageYOffset + -120, behavior: 'smooth'});
},
handleScroll () {
let currentCategory = null;
for (let category of this.subListCategories) {
var elementRelativeToViewport = document.getElementById(category.id).getBoundingClientRect().y;
if (elementRelativeToViewport > 0 && elementRelativeToViewport < window.innerHeight / 2) {
currentCategory = category;
break;
}
}
if (currentCategory) {
this.subCategoryTabIndex = this.subListCategories.indexOf(currentCategory);
}
}
}
}
</script>

<style scoped>
.tabs {
margin-top: 0.75rem;
}
.tabs >>> .nav-link {
font-size: 13px;
padding: 1px 8px;
border-radius: 6px;
margin-right: 8px;
}
.tabs >>> .nav-link:not(.active) {
color: #333;
font-weight: 500;
background-color: #f8f8f8;
}
.list-header-group {
position: sticky;
top: 15px;
Expand Down

0 comments on commit 28a3199

Please sign in to comment.