Skip to content

Commit

Permalink
chore: updated branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszjedrasik committed Jan 5, 2021
1 parent bde1e74 commit 9447532
Show file tree
Hide file tree
Showing 17 changed files with 418 additions and 67 deletions.
71 changes: 58 additions & 13 deletions packages/boilerplate/api-client/src/api/getCategory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,115 @@ export default async function getCategory(context, params, customQuery?: CustomQ
return Promise.resolve([
{
id: 1,
name: 'New',
slug: 'new',
children: [
{
id: 15,
name: 'Women',
slug: 'new-women',
children: [
{
id: 16,
name: 'Clothing',
slug: 'new-women-clothing',
children: []
},
{
id: 17,
name: 'Shoes',
slug: 'new-women-shoes',
children: []
}
]
},
{
id: 11,
name: 'Men',
slug: 'new-men',
children: [
{
id: 18,
name: 'Clothing',
slug: 'new-men-clothing',
children: []
},
{
id: 19,
name: 'Shoes',
slug: 'new-men-shoes',
children: []
}
]
}
]
},
{
id: 2,
name: 'Women',
slug: 'women',
items: [
children: [
{
id: 4,
name: 'Women jackets',
slug: 'women-jackets',
items: [
children: [
{
id: 9,
name: 'Winter jackets',
slug: 'winter-jackets',
items: []
children: []
},
{
id: 10,
name: 'Autumn jackets',
slug: 'autmun-jackets',
items: []
children: []
}
]
},
{
id: 5,
name: 'Skirts',
slug: 'skirts',
items: []
children: []
}
]
},
{
id: 2,
id: 3,
name: 'Men',
slug: 'men',
items: [
children: [
{
id: 6,
name: 'Men T-shirts',
slug: 'men-tshirts',
items: []
children: []
}
]
},
{
id: 3,
id: 4,
name: 'Kids',
slug: 'kids',
items: [
children: [
{
id: 7,
name: 'Toys',
slug: 'toys',
items: [
children: [
{
id: 8,
name: 'Toy Cars',
slug: 'toy-cars',
items: []
children: []
},
{
id: 8,
name: 'Dolls',
slug: 'dolls',
items: []
children: []
}
]
}
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import gql from 'graphql-tag';
import { CategoryFragment } from './../../fragments';

export default gql`
fragment Children on Category {
id
slug(acceptLanguage: $acceptLanguage)
name(acceptLanguage: $acceptLanguage)
childCount
}
${CategoryFragment}
fragment DefaultCategory on Category {
fragment Children on Category {
id
slug(acceptLanguage: $acceptLanguage)
name(acceptLanguage: $acceptLanguage)
childCount
children {
...Children
children {
...Children
children {
...Children
}
}
}
}
query categories($where: String, $sort: [String!], $limit: Int, $offset: Int, $acceptLanguage: [Locale!]) {
Expand Down
17 changes: 17 additions & 0 deletions packages/commercetools/api-client/src/fragments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,20 @@ export const OrderFragment = `
}
`;

export const CategoryFragment = `
fragment DefaultCategory on Category {
id
slug(acceptLanguage: $acceptLanguage)
name(acceptLanguage: $acceptLanguage)
childCount
children {
...Children
children {
...Children
children {
...Children
}
}
}
}
`;
95 changes: 95 additions & 0 deletions packages/commercetools/theme/components/header/HeaderNav.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<template>
<SfHeaderNavigation>
<SfHeaderNavigationItem
v-for="(category, index) in categories"
:key="index"
:label="category.name"
@mouseenter="() => handleMouseEnter(category.slug)"
@mouseleave="() => handleMouseLeave()"
@click="handleMouseLeave()"
:link="localePath(`/c/${category.slug}`)"
>
<SfMegaMenu
:is-absolute="true"
:visible="currentCatSlug === category.slug"
:title="category.name"
@close="currentCatSlug = ''"
v-if="category && category.children.length"
>
<SfMegaMenuColumn
v-for="(subCategory, subIndex) in category.children"
:key="subIndex"
:title="subCategory.name"
>
<SfLoader :loading="subCategoriesLoading">
<SfList>
<SfListItem
v-for="(subCategoryChild, childIndex) in subCategory.children"
:key="childIndex"
>
<SfMenuItem :label="subCategoryChild.name" :link="localePath(`/c/${subCategoryChild.slug}`)">
<SfLink>
{{ subCategoryChild.name }}
</SfLink>
</SfMenuItem>
</SfListItem>
</SfList>
</SfLoader>
</SfMegaMenuColumn>
<NewCatBanners v-if="currentCatSlug === 'new'" />
</SfMegaMenu>
</SfHeaderNavigationItem>
</SfHeaderNavigation>
</template>

<script>
import { SfMegaMenu, SfMenuItem, SfList, SfBanner, SfLoader } from '@storefront-ui/vue';
import { useCategory } from '@vue-storefront/commercetools';
import { onSSR } from '@vue-storefront/core';
import { ref } from '@vue/composition-api';
import { rootCategoriesQuery } from '../../queries/topCategories';
import debounce from 'lodash.debounce';
export default {
name: 'HeaderNav',
components: {
SfMegaMenu,
SfMenuItem,
SfList,
SfBanner,
SfLoader,
NewCatBanners: () => import('./NewCatBanners')
},
setup (_, { emit }) {
const { categories, search } = useCategory('menu-categories');
const { categories: subCategories, search: subCategoriesSearch, loading: subCategoriesLoading } = useCategory('menu-subCategories');
const currentCatSlug = ref('');
const handleMouseEnter = debounce((slug) => {
if (currentCatSlug.value) return;
emit('setOverlay', true);
currentCatSlug.value = slug;
subCategoriesSearch({ slug });
}, 200);
const handleMouseLeave = debounce(() => {
emit('setOverlay', false);
currentCatSlug.value = '';
}, 200);
onSSR(async () => {
await search({ customQuery: rootCategoriesQuery });
});
return {
categories,
subCategories,
currentCatSlug,
subCategoriesLoading,
handleMouseEnter,
handleMouseLeave
};
}
};
</script>
36 changes: 36 additions & 0 deletions packages/commercetools/theme/queries/topCategories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import gql from 'graphql-tag';
import { CategoryFragment } from '@vue-storefront/commercetools-api';

const customQuery = gql`
${CategoryFragment}
fragment Children on Category {
id
slug(acceptLanguage: $acceptLanguage)
name(acceptLanguage: $acceptLanguage)
childCount
}
query categories($where: String, $sort: [String!], $limit: Int, $offset: Int, $acceptLanguage: [Locale!]) {
categories(where: $where, sort: $sort, limit: $limit, offset: $offset) {
offset
count
total
results {
...DefaultCategory
}
}
}
`;

export const rootCategoriesQuery = (query, variables) => {
const customVariables = {
...variables,
where: 'parent is not defined'
};

return {
query: customQuery,
variables: customVariables
};
};
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions packages/core/docs/commercetools/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## 1.1.0 (not released)
- added MegaMenu to theme ([#5267](https://github.com/vuestorefront/vue-storefront/issues/5267))
- fix getOrders api ([#5328](https://github.com/DivanteLtd/vue-storefront/issues/5328))
- added bottom margin to fix visibility of last footer category ([#5253](https://github.com/DivanteLtd/vue-storefront/issues/5253))
- [BREAKING] refactored names of many factory methods and composable methods, details in linked PR ([#5299](https://github.com/DivanteLtd/vue-storefront/pull/5299))
Expand Down
1 change: 1 addition & 0 deletions packages/core/docs/contributing/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## 2.2.0 (not released)
- added MegaMenu to theme ([#5267](https://github.com/vuestorefront/vue-storefront/issues/5267))
- added bottom margin to fix visibility of last footer category ([#5253](https://github.com/DivanteLtd/vue-storefront/issues/5253))
- [BREAKING] refactored names of many factory methods and composable methods, details in linked PR ([#5299](https://github.com/DivanteLtd/vue-storefront/pull/5299))
- [BREAKING] changed signatures of factory methods to always 2 arguments, details in linked PR ([#5299](https://github.com/DivanteLtd/vue-storefront/pull/5299))
Expand Down
1 change: 1 addition & 0 deletions packages/core/nuxt-theme-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"access": "public"
},
"dependencies": {
"lodash.debounce": "^4.0.8",
"lodash.merge": "^4.6.2"
}
}

0 comments on commit 9447532

Please sign in to comment.