11<template >
2- <div >
3- <slot
4- v-if =" !$fetchState.pending"
5- name =" content"
6- :category-tree =" categoryTree"
7- :active-category =" activeCategory"
2+ <SfAccordion
3+ :open =" activeCategory"
4+ :show-chevron =" true"
5+ >
6+ <SfAccordionItem
7+ v-for =" (cat, i) in categoryTree.items"
8+ :key =" i"
9+ :header =" cat.label"
810 >
9- <SfAccordion
10- :open =" activeCategory"
11- :show-chevron =" true"
12- >
13- <SfAccordionItem
14- v-for =" (cat, i) in categoryTree.items"
15- :key =" i"
16- :header =" cat.label"
11+ <SfList class =" list" >
12+ <SfListItem
13+ v-for =" (subCat, j) in cat.items"
14+ :key =" j"
15+ class =" list__item"
1716 >
18- <SfList class =" list" >
19- <SfListItem
20- v-for =" (subCat, j) in cat.items"
21- :key =" j"
22- class =" list__item"
23- >
24- <SfMenuItem
25- :count =" subCat.count || ''"
26- :label =" subCat.label"
17+ <SfMenuItem
18+ :count =" subCat.count || ''"
19+ :label =" subCat.label"
20+ >
21+ <template #label =" { label } " >
22+ <nuxt-link
23+ :to =" localePath(getAgnosticCatLink(subCat))"
24+ :class =" subCat.isCurrent ? 'sidebar--cat-selected' : ''"
2725 >
28- < template # label = " { label }" >
29- < nuxt-link
30- :to = " localePath(getAgnosticCatLink(subCat)) "
31- :class = " subCat.isCurrent ? 'sidebar--cat-selected' : '' "
32- >
33- {{ label }}
34- </ nuxt-link >
35- </ template >
36- </ SfMenuItem >
37- < SfMenuItem
38- v-for = " (subSubCat, z) in subCat.items && subCat.items "
39- :key = " z "
40- :count = " subSubCat.count || '' "
41- :label = " subSubCat.label "
42- class =" list__item__sub "
26+ {{ label }}
27+ </ nuxt-link >
28+ </ template >
29+ </ SfMenuItem >
30+ < SfMenuItem
31+ v-for = " (subSubCat, z) in subCat.items "
32+ :key = " z "
33+ :count = " subSubCat.count || '' "
34+ :label = " subSubCat.label "
35+ class = " list__item__sub "
36+ >
37+ < template # label = " { label } " >
38+ < nuxt-link
39+ :to = " localePath(getAgnosticCatLink( subSubCat)) "
40+ : class =" {'sidebar--cat-selected': subSubCat.isCurrent} "
4341 >
44- <template #label =" { label } " >
45- <nuxt-link
46- :to =" localePath(getAgnosticCatLink(subSubCat))"
47- :class =" subSubCat.isCurrent ? 'sidebar--cat-selected' : ''"
48- >
49- {{ label }}
50- </nuxt-link >
51- </template >
52- </SfMenuItem >
53- </SfListItem >
54- </SfList >
55- </SfAccordionItem >
56- </SfAccordion >
57- </slot >
58- </div >
42+ {{ label }}
43+ </nuxt-link >
44+ </template >
45+ </SfMenuItem >
46+ </SfListItem >
47+ </SfList >
48+ </SfAccordionItem >
49+ </SfAccordion >
5950</template >
6051
6152<script >
62- import findDeep from ' deepdash/findDeep' ;
6353import {
6454 SfList ,
6555 SfMenuItem ,
6656 SfAccordion ,
67- SfDivider ,
6857} from ' @storefront-ui/vue' ;
6958import {
70- computed ,
7159 defineComponent ,
72- ref ,
73- useFetch ,
7460} from ' @nuxtjs/composition-api' ;
75- import {
76- categoryGetters ,
77- useCategory ,
78- } from ' @vue-storefront/magento' ;
79- import { CacheTagPrefix , useCache } from ' @vue-storefront/cache' ;
80- import { useUrlResolver } from ' ~/composables/useUrlResolver.ts' ;
61+
8162import { useUiHelpers } from ' ~/composables' ;
8263
8364export default defineComponent ({
@@ -86,57 +67,22 @@ export default defineComponent({
8667 SfList,
8768 SfMenuItem,
8869 SfAccordion,
89- SfDivider,
70+ },
71+ props: {
72+ categoryTree: {
73+ type: Object ,
74+ default : () => {},
75+ },
76+ activeCategory: {
77+ type: String ,
78+ default: ' ' ,
79+ },
9080 },
9181 setup () {
9282 const uiHelpers = useUiHelpers ();
93- const { addTags } = useCache ();
94-
95- const {
96- result: urlData ,
97- search: resolveUrl ,
98- } = useUrlResolver ();
99-
100- const {
101- categories ,
102- search ,
103- } = useCategory (' categoryList-sidebar' );
104-
105- const categoryTree = ref ([]);
106- const activeCategory = computed (() => {
107- const items = categoryTree .value ? .items ;
108- if (! items) {
109- return ' ' ;
110- }
111- const categoryLabel = ref ();
112- const parent = findDeep (items, (value , key , parentValue , _deepCtx ) => {
113- if (key === ' isCurrent' && value) {
114- // eslint-disable-next-line no-underscore-dangle
115- categoryLabel .value = _deepCtx .obj [_deepCtx ._item .path [0 ]].label ;
116- }
117- return key === ' isCurrent' && value;
118- });
119-
120- return categoryLabel .value || parent? .category ? .label || items[0 ]? .label ;
121- });
122-
123- useFetch (async () => {
124- await Promise .all ([resolveUrl (), search ({ pageSize: 20 })]);
125- categoryTree .value = categoryGetters .getCategoryTree (
126- categories .value ? .[0 ],
127- urlData .value ? .entity_uid ,
128- false ,
129- );
130-
131- const categoriesTags = categoryTree? .value ? .items ? .map ((category ) => ({ prefix: CacheTagPrefix .Category , value: category .uid }));
132- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
133- addTags (categoriesTags);
134- });
13583
13684 return {
13785 ... uiHelpers,
138- categoryTree,
139- activeCategory,
14086 };
14187 },
14288});
0 commit comments