@wix/headless-stores 0.0.76 → 0.0.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/dist/react/Category.d.ts +4 -8
- package/cjs/dist/react/Category.js +35 -29
- package/cjs/dist/react/CategoryList.d.ts +3 -2
- package/cjs/dist/react/CategoryList.js +4 -3
- package/cjs/dist/react/ProductList.d.ts +1 -1
- package/cjs/dist/react/ProductList.js +1 -1
- package/cjs/dist/react/core/CategoryList.d.ts +11 -5
- package/cjs/dist/react/core/CategoryList.js +9 -4
- package/cjs/dist/react/core/ProductListFilters.d.ts +1 -1
- package/cjs/dist/react/index.d.ts +0 -1
- package/cjs/dist/react/index.js +0 -1
- package/cjs/dist/services/categories-list-service.d.ts +2 -1
- package/cjs/dist/services/index.d.ts +0 -1
- package/cjs/dist/services/index.js +0 -1
- package/cjs/dist/services/products-list-service.d.ts +2 -1
- package/dist/react/Category.d.ts +4 -8
- package/dist/react/Category.js +35 -29
- package/dist/react/CategoryList.d.ts +3 -2
- package/dist/react/CategoryList.js +4 -3
- package/dist/react/ProductList.d.ts +1 -1
- package/dist/react/ProductList.js +1 -1
- package/dist/react/core/CategoryList.d.ts +11 -5
- package/dist/react/core/CategoryList.js +9 -4
- package/dist/react/core/ProductListFilters.d.ts +1 -1
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -1
- package/dist/services/categories-list-service.d.ts +2 -1
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/dist/services/products-list-service.d.ts +2 -1
- package/package.json +2 -2
- package/cjs/dist/react/core/Category.d.ts +0 -98
- package/cjs/dist/react/core/Category.js +0 -81
- package/cjs/dist/services/category-service.d.ts +0 -161
- package/cjs/dist/services/category-service.js +0 -149
- package/dist/react/core/Category.d.ts +0 -98
- package/dist/react/core/Category.js +0 -81
- package/dist/services/category-service.d.ts +0 -161
- package/dist/services/category-service.js +0 -149
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
2
3
|
import { useService, WixServices } from '@wix/services-manager-react';
|
|
3
4
|
import { createServicesMap } from '@wix/services-manager';
|
|
4
5
|
import { CategoriesListService, CategoriesListServiceDefinition, } from '../../services/categories-list-service.js';
|
|
5
|
-
import { Root as CategoryRoot } from './Category.js';
|
|
6
6
|
/**
|
|
7
7
|
* Root component that provides the CategoryList service context to its children.
|
|
8
8
|
* This component sets up the necessary services for managing categories list state.
|
|
9
|
+
* Optionally connects to ProductList filtering when connectToProductFilter is enabled.
|
|
9
10
|
*
|
|
10
11
|
* @order 1
|
|
11
12
|
* @component
|
|
@@ -15,7 +16,10 @@ import { Root as CategoryRoot } from './Category.js';
|
|
|
15
16
|
*
|
|
16
17
|
* function CategoriesPage() {
|
|
17
18
|
* return (
|
|
18
|
-
* <CategoryList.Root
|
|
19
|
+
* <CategoryList.Root
|
|
20
|
+
* categoriesListConfig={{ categories: myCategories }}
|
|
21
|
+
* connectToProductFilter={true}
|
|
22
|
+
* >
|
|
19
23
|
* <CategoryList.ItemContent>
|
|
20
24
|
* {({ category }) => (
|
|
21
25
|
* <div key={category._id}>
|
|
@@ -29,7 +33,8 @@ import { Root as CategoryRoot } from './Category.js';
|
|
|
29
33
|
* ```
|
|
30
34
|
*/
|
|
31
35
|
export function Root(props) {
|
|
32
|
-
|
|
36
|
+
const { categoriesListConfig, children } = props;
|
|
37
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(CategoriesListServiceDefinition, CategoriesListService, categoriesListConfig), children: children }));
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
40
|
* Component that renders content when the categories list is empty.
|
|
@@ -166,7 +171,7 @@ export function ItemContent(props) {
|
|
|
166
171
|
if (isLoading.get() || error.get() || categoriesValue.length === 0) {
|
|
167
172
|
return null;
|
|
168
173
|
}
|
|
169
|
-
return categoriesValue.map((category) => (_jsx(
|
|
174
|
+
return categoriesValue.map((category) => (_jsx(React.Fragment, { children: typeof props.children === 'function'
|
|
170
175
|
? props.children({
|
|
171
176
|
category,
|
|
172
177
|
})
|
|
@@ -50,7 +50,7 @@ export interface ResetTriggerRenderProps {
|
|
|
50
50
|
export declare function ResetTrigger(props: ResetTriggerProps): ReactNode;
|
|
51
51
|
export interface CategoryFilterRenderProps {
|
|
52
52
|
selectedCategory: Category | null;
|
|
53
|
-
setSelectedCategory: (category: Category) => void;
|
|
53
|
+
setSelectedCategory: (category: Category | null) => void;
|
|
54
54
|
}
|
|
55
55
|
export interface CategoryFilterProps {
|
|
56
56
|
/** Content to display (can be a render function receiving category data or ReactNode) */
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * as CategoryListCore from './core/CategoryList.js';
|
|
2
|
-
export * as CategoryCore from './core/Category.js';
|
|
3
2
|
export * as ProductCore from './core/Product.js';
|
|
4
3
|
export * as ProductModifiers from './core/ProductModifiers.js';
|
|
5
4
|
export * as ProductListCore from './core/ProductList.js';
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * as CategoryListCore from './core/CategoryList.js';
|
|
2
|
-
export * as CategoryCore from './core/Category.js';
|
|
3
2
|
export * as ProductCore from './core/Product.js';
|
|
4
3
|
export * as ProductModifiers from './core/ProductModifiers.js';
|
|
5
4
|
export * as ProductListCore from './core/ProductList.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Signal } from '@wix/services-definitions/core-services/signals';
|
|
2
|
-
import {
|
|
2
|
+
import { categories } from '@wix/categories';
|
|
3
|
+
export type Category = categories.Category;
|
|
3
4
|
/**
|
|
4
5
|
* Configuration interface for the Categories List service.
|
|
5
6
|
* Contains the initial categories data that will be loaded into the service.
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { CategoryService, CategoryServiceDefinition, loadCategoryServiceConfig, CategoryServiceConfig, Category, } from './category-service.js';
|
|
2
1
|
export { CategoriesListService, CategoriesListServiceDefinition, loadCategoriesListServiceConfig, CategoriesListServiceConfig, } from './categories-list-service.js';
|
|
3
2
|
export { ProductModifiersService, ProductModifiersServiceDefinition, } from './product-modifiers-service.js';
|
|
4
3
|
export { ProductService, ProductServiceDefinition, loadProductServiceConfig, } from './product-service.js';
|
package/dist/services/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { CategoryService, CategoryServiceDefinition, loadCategoryServiceConfig, } from './category-service.js';
|
|
2
1
|
export { CategoriesListService, CategoriesListServiceDefinition, loadCategoriesListServiceConfig, } from './categories-list-service.js';
|
|
3
2
|
export { ProductModifiersService, ProductModifiersServiceDefinition, } from './product-modifiers-service.js';
|
|
4
3
|
export { ProductService, ProductServiceDefinition, loadProductServiceConfig, } from './product-service.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Signal, type ReadOnlySignal } from '@wix/services-definitions/core-services/signals';
|
|
2
2
|
import { customizationsV3, productsV3 } from '@wix/stores';
|
|
3
|
-
import {
|
|
3
|
+
import { categories } from '@wix/categories';
|
|
4
|
+
type Category = categories.Category;
|
|
4
5
|
export declare const DEFAULT_QUERY_LIMIT = 100;
|
|
5
6
|
import { SortType } from './../enums/sort-enums.js';
|
|
6
7
|
export { SortType } from './../enums/sort-enums.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-stores",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.78",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@wix/ecom": "^1.0.1278",
|
|
64
64
|
"@wix/essentials": "^0.1.24",
|
|
65
65
|
"@wix/headless-components": "0.0.12",
|
|
66
|
-
"@wix/headless-ecom": "0.0.
|
|
66
|
+
"@wix/headless-ecom": "0.0.25",
|
|
67
67
|
"@wix/headless-media": "0.0.11",
|
|
68
68
|
"@wix/headless-utils": "0.0.3",
|
|
69
69
|
"@wix/redirects": "^1.0.83",
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { type CategoryServiceConfig } from '../../services/category-service.js';
|
|
2
|
-
export interface RootProps {
|
|
3
|
-
children: React.ReactNode;
|
|
4
|
-
categoryServiceConfig: CategoryServiceConfig;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Root component that provides the Category service context to its children.
|
|
8
|
-
* This component sets up the necessary services for managing category state.
|
|
9
|
-
*
|
|
10
|
-
* @order 1
|
|
11
|
-
* @component
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* import { CategoryCore } from '@wix/stores/components';
|
|
15
|
-
*
|
|
16
|
-
* function CategoryPage() {
|
|
17
|
-
* return (
|
|
18
|
-
* <Category.Root categoryServiceConfig={{ category: myCategory }}>
|
|
19
|
-
* <Category.Name>
|
|
20
|
-
* {({ name }) => <h1>{name}</h1>}
|
|
21
|
-
* </Category.Name>
|
|
22
|
-
* <Category.Slug>
|
|
23
|
-
* {({ slug }) => <p>Slug: {slug}</p>}
|
|
24
|
-
* </Category.Slug>
|
|
25
|
-
* </Category.Root>
|
|
26
|
-
* );
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare function Root(props: RootProps): React.ReactNode;
|
|
31
|
-
/**
|
|
32
|
-
* Props for Name headless component
|
|
33
|
-
*/
|
|
34
|
-
export interface NameProps {
|
|
35
|
-
/** Content to display (can be a render function receiving name data or ReactNode) */
|
|
36
|
-
children: ((props: NameRenderProps) => React.ReactNode) | React.ReactNode;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Render props for Name component
|
|
40
|
-
*/
|
|
41
|
-
export interface NameRenderProps {
|
|
42
|
-
/** Category name */
|
|
43
|
-
name: string;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Headless component for category name display
|
|
47
|
-
*
|
|
48
|
-
* @component
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* import { CategoryCore } from '@wix/stores/components';
|
|
52
|
-
*
|
|
53
|
-
* function CategoryHeader() {
|
|
54
|
-
* return (
|
|
55
|
-
* <Category.Name>
|
|
56
|
-
* {({ name }) => (
|
|
57
|
-
* <h1 className="category-title">{name}</h1>
|
|
58
|
-
* )}
|
|
59
|
-
* </Category.Name>
|
|
60
|
-
* );
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export declare function Name(props: NameProps): import("react").ReactNode;
|
|
65
|
-
/**
|
|
66
|
-
* Props for Slug headless component
|
|
67
|
-
*/
|
|
68
|
-
export interface SlugProps {
|
|
69
|
-
/** Content to display (can be a render function receiving slug data or ReactNode) */
|
|
70
|
-
children: ((props: SlugRenderProps) => React.ReactNode) | React.ReactNode;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Render props for Slug component
|
|
74
|
-
*/
|
|
75
|
-
export interface SlugRenderProps {
|
|
76
|
-
/** Category slug */
|
|
77
|
-
slug: string;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Headless component for category slug display
|
|
81
|
-
*
|
|
82
|
-
* @component
|
|
83
|
-
* @example
|
|
84
|
-
* ```tsx
|
|
85
|
-
* import { CategoryCore } from '@wix/stores/components';
|
|
86
|
-
*
|
|
87
|
-
* function CategoryInfo() {
|
|
88
|
-
* return (
|
|
89
|
-
* <Category.Slug>
|
|
90
|
-
* {({ slug }) => (
|
|
91
|
-
* <p className="category-slug">Category slug: {slug}</p>
|
|
92
|
-
* )}
|
|
93
|
-
* </Category.Slug>
|
|
94
|
-
* );
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export declare function Slug(props: SlugProps): import("react").ReactNode;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createServicesMap } from '@wix/services-manager';
|
|
3
|
-
import { useService, WixServices } from '@wix/services-manager-react';
|
|
4
|
-
import { CategoryService, CategoryServiceDefinition, } from '../../services/category-service.js';
|
|
5
|
-
/**
|
|
6
|
-
* Root component that provides the Category service context to its children.
|
|
7
|
-
* This component sets up the necessary services for managing category state.
|
|
8
|
-
*
|
|
9
|
-
* @order 1
|
|
10
|
-
* @component
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* import { CategoryCore } from '@wix/stores/components';
|
|
14
|
-
*
|
|
15
|
-
* function CategoryPage() {
|
|
16
|
-
* return (
|
|
17
|
-
* <Category.Root categoryServiceConfig={{ category: myCategory }}>
|
|
18
|
-
* <Category.Name>
|
|
19
|
-
* {({ name }) => <h1>{name}</h1>}
|
|
20
|
-
* </Category.Name>
|
|
21
|
-
* <Category.Slug>
|
|
22
|
-
* {({ slug }) => <p>Slug: {slug}</p>}
|
|
23
|
-
* </Category.Slug>
|
|
24
|
-
* </Category.Root>
|
|
25
|
-
* );
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export function Root(props) {
|
|
30
|
-
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(CategoryServiceDefinition, CategoryService, props.categoryServiceConfig), children: props.children }));
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Headless component for category name display
|
|
34
|
-
*
|
|
35
|
-
* @component
|
|
36
|
-
* @example
|
|
37
|
-
* ```tsx
|
|
38
|
-
* import { CategoryCore } from '@wix/stores/components';
|
|
39
|
-
*
|
|
40
|
-
* function CategoryHeader() {
|
|
41
|
-
* return (
|
|
42
|
-
* <Category.Name>
|
|
43
|
-
* {({ name }) => (
|
|
44
|
-
* <h1 className="category-title">{name}</h1>
|
|
45
|
-
* )}
|
|
46
|
-
* </Category.Name>
|
|
47
|
-
* );
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export function Name(props) {
|
|
52
|
-
const categoryService = useService(CategoryServiceDefinition);
|
|
53
|
-
return typeof props.children === 'function'
|
|
54
|
-
? props.children({ name: categoryService.category.get().name })
|
|
55
|
-
: props.children;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Headless component for category slug display
|
|
59
|
-
*
|
|
60
|
-
* @component
|
|
61
|
-
* @example
|
|
62
|
-
* ```tsx
|
|
63
|
-
* import { CategoryCore } from '@wix/stores/components';
|
|
64
|
-
*
|
|
65
|
-
* function CategoryInfo() {
|
|
66
|
-
* return (
|
|
67
|
-
* <Category.Slug>
|
|
68
|
-
* {({ slug }) => (
|
|
69
|
-
* <p className="category-slug">Category slug: {slug}</p>
|
|
70
|
-
* )}
|
|
71
|
-
* </Category.Slug>
|
|
72
|
-
* );
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export function Slug(props) {
|
|
77
|
-
const categoryService = useService(CategoryServiceDefinition);
|
|
78
|
-
return typeof props.children === 'function'
|
|
79
|
-
? props.children({ slug: categoryService.category.get().slug })
|
|
80
|
-
: props.children;
|
|
81
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { categories } from '@wix/categories';
|
|
2
|
-
import { type Signal } from '@wix/services-definitions/core-services/signals';
|
|
3
|
-
/**
|
|
4
|
-
* Type representing a category from the Wix Categories API.
|
|
5
|
-
* This type is used to define the structure of category objects in the service.
|
|
6
|
-
*
|
|
7
|
-
* @type Category
|
|
8
|
-
*/
|
|
9
|
-
export type Category = categories.Category;
|
|
10
|
-
export interface CategoryServiceAPI {
|
|
11
|
-
/** Reactive signal containing the current category data */
|
|
12
|
-
category: Signal<Category>;
|
|
13
|
-
/** Reactive signal indicating if a category is currently selected */
|
|
14
|
-
isSelected: Signal<boolean>;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Service definition for the Category service.
|
|
18
|
-
* This defines the reactive API contract for managing a single product category.
|
|
19
|
-
*
|
|
20
|
-
* @constant
|
|
21
|
-
*/
|
|
22
|
-
export declare const CategoryServiceDefinition: string & {
|
|
23
|
-
__api: CategoryServiceAPI;
|
|
24
|
-
__config: {};
|
|
25
|
-
isServiceDefinition?: boolean;
|
|
26
|
-
} & CategoryServiceAPI;
|
|
27
|
-
/**
|
|
28
|
-
* Configuration interface for the Category service.
|
|
29
|
-
* Contains the initial category data that will be loaded into the service.
|
|
30
|
-
*
|
|
31
|
-
* @interface CategoryServiceConfig
|
|
32
|
-
*/
|
|
33
|
-
export type CategoryServiceConfig = {
|
|
34
|
-
/** The category object to initialize the service with */
|
|
35
|
-
category: Category;
|
|
36
|
-
/** Whether the category is currently selected */
|
|
37
|
-
isSelected?: boolean;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Implementation of the Category service that manages reactive category data.
|
|
41
|
-
* This service provides a signal for category data and maintains it in a reactive state.
|
|
42
|
-
* The service is initialized with pre-loaded category data.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```tsx
|
|
46
|
-
* import { CategoryService, CategoryServiceDefinition } from '@wix/stores/services';
|
|
47
|
-
* import { useService } from '@wix/services-manager-react';
|
|
48
|
-
*
|
|
49
|
-
* function CategoryComponent({ categoryConfig }) {
|
|
50
|
-
* return (
|
|
51
|
-
* <ServiceProvider services={createServicesMap([
|
|
52
|
-
* [CategoryServiceDefinition, CategoryService.withConfig(categoryConfig)]
|
|
53
|
-
* ])}>
|
|
54
|
-
* <CategoryDisplay />
|
|
55
|
-
* </ServiceProvider>
|
|
56
|
-
* );
|
|
57
|
-
* }
|
|
58
|
-
*
|
|
59
|
-
* function CategoryDisplay() {
|
|
60
|
-
* const categoryService = useService(CategoryServiceDefinition);
|
|
61
|
-
* const category = categoryService.category.get();
|
|
62
|
-
*
|
|
63
|
-
* return (
|
|
64
|
-
* <div>
|
|
65
|
-
* <h1>{category.name}</h1>
|
|
66
|
-
* <p>{category.description}</p>
|
|
67
|
-
* </div>
|
|
68
|
-
* );
|
|
69
|
-
* }
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export declare const CategoryService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
73
|
-
__api: CategoryServiceAPI;
|
|
74
|
-
__config: {};
|
|
75
|
-
isServiceDefinition?: boolean;
|
|
76
|
-
} & CategoryServiceAPI, CategoryServiceConfig>;
|
|
77
|
-
/**
|
|
78
|
-
* Loads category service configuration from the Wix Categories API for SSR initialization.
|
|
79
|
-
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
80
|
-
* a specific category by slug that will be used to configure the CategoryService.
|
|
81
|
-
*
|
|
82
|
-
* @param {string} slug - The category slug to load
|
|
83
|
-
* @returns {Promise} Promise that resolves to either success with config or not-found result
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```astro
|
|
87
|
-
* ---
|
|
88
|
-
* // Astro page example - pages/category/[slug].astro
|
|
89
|
-
* import { loadCategoryServiceConfig } from '@wix/stores/services';
|
|
90
|
-
* import { Category } from '@wix/stores/components/react';
|
|
91
|
-
*
|
|
92
|
-
* // Get category slug from URL params
|
|
93
|
-
* const { slug } = Astro.params;
|
|
94
|
-
*
|
|
95
|
-
* // Load category data during SSR
|
|
96
|
-
* const categoryResult = await loadCategoryServiceConfig(slug);
|
|
97
|
-
*
|
|
98
|
-
* // Handle not found case
|
|
99
|
-
* if (categoryResult.type === 'not-found') {
|
|
100
|
-
* return Astro.redirect('/404');
|
|
101
|
-
* }
|
|
102
|
-
* ---
|
|
103
|
-
*
|
|
104
|
-
* <Category.Root categoryConfig={categoryResult.config}>
|
|
105
|
-
* <Category.Name>
|
|
106
|
-
* {({ name }) => <h1>{name}</h1>}
|
|
107
|
-
* </Category.Name>
|
|
108
|
-
* </Category.Root>
|
|
109
|
-
* ```
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```tsx
|
|
113
|
-
* // Next.js page example - pages/category/[slug].tsx
|
|
114
|
-
* import { GetServerSideProps } from 'next';
|
|
115
|
-
* import { loadCategoryServiceConfig } from '@wix/stores/services';
|
|
116
|
-
* import { Category } from '@wix/stores/components/react';
|
|
117
|
-
*
|
|
118
|
-
* interface CategoryPageProps {
|
|
119
|
-
* categoryConfig: Awaited<ReturnType<typeof loadCategoryServiceConfig>>['config'];
|
|
120
|
-
* }
|
|
121
|
-
*
|
|
122
|
-
* export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async ({ params }) => {
|
|
123
|
-
* const slug = params?.slug as string;
|
|
124
|
-
*
|
|
125
|
-
* // Load category data during SSR
|
|
126
|
-
* const categoryResult = await loadCategoryServiceConfig(slug);
|
|
127
|
-
*
|
|
128
|
-
* // Handle not found case
|
|
129
|
-
* if (categoryResult.type === 'not-found') {
|
|
130
|
-
* return {
|
|
131
|
-
* notFound: true,
|
|
132
|
-
* };
|
|
133
|
-
* }
|
|
134
|
-
*
|
|
135
|
-
* return {
|
|
136
|
-
* props: {
|
|
137
|
-
* categoryConfig: categoryResult.config,
|
|
138
|
-
* },
|
|
139
|
-
* };
|
|
140
|
-
* };
|
|
141
|
-
*
|
|
142
|
-
* export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
|
|
143
|
-
* return (
|
|
144
|
-
* <Category.Root categoryConfig={categoryConfig}>
|
|
145
|
-
* <Category.Name>
|
|
146
|
-
* {({ name }) => <h1>{name}</h1>}
|
|
147
|
-
* </Category.Name>
|
|
148
|
-
* </Category.Root>
|
|
149
|
-
* );
|
|
150
|
-
* }
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
export declare function loadCategoryServiceConfig(slug: string): Promise<{
|
|
154
|
-
/** Type "success" means that the category was found and the config is valid */
|
|
155
|
-
type: 'success';
|
|
156
|
-
/** The category config containing the loaded category data */
|
|
157
|
-
config: CategoryServiceConfig;
|
|
158
|
-
} | {
|
|
159
|
-
/** Type "not-found" means that the category was not found */
|
|
160
|
-
type: 'not-found';
|
|
161
|
-
}>;
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { defineService, implementService } from '@wix/services-definitions';
|
|
2
|
-
import { categories } from '@wix/categories';
|
|
3
|
-
import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
|
|
4
|
-
/**
|
|
5
|
-
* Service definition for the Category service.
|
|
6
|
-
* This defines the reactive API contract for managing a single product category.
|
|
7
|
-
*
|
|
8
|
-
* @constant
|
|
9
|
-
*/
|
|
10
|
-
export const CategoryServiceDefinition = defineService('category');
|
|
11
|
-
/**
|
|
12
|
-
* Implementation of the Category service that manages reactive category data.
|
|
13
|
-
* This service provides a signal for category data and maintains it in a reactive state.
|
|
14
|
-
* The service is initialized with pre-loaded category data.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* import { CategoryService, CategoryServiceDefinition } from '@wix/stores/services';
|
|
19
|
-
* import { useService } from '@wix/services-manager-react';
|
|
20
|
-
*
|
|
21
|
-
* function CategoryComponent({ categoryConfig }) {
|
|
22
|
-
* return (
|
|
23
|
-
* <ServiceProvider services={createServicesMap([
|
|
24
|
-
* [CategoryServiceDefinition, CategoryService.withConfig(categoryConfig)]
|
|
25
|
-
* ])}>
|
|
26
|
-
* <CategoryDisplay />
|
|
27
|
-
* </ServiceProvider>
|
|
28
|
-
* );
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* function CategoryDisplay() {
|
|
32
|
-
* const categoryService = useService(CategoryServiceDefinition);
|
|
33
|
-
* const category = categoryService.category.get();
|
|
34
|
-
*
|
|
35
|
-
* return (
|
|
36
|
-
* <div>
|
|
37
|
-
* <h1>{category.name}</h1>
|
|
38
|
-
* <p>{category.description}</p>
|
|
39
|
-
* </div>
|
|
40
|
-
* );
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export const CategoryService = implementService.withConfig()(CategoryServiceDefinition, ({ getService, config }) => {
|
|
45
|
-
const signalsService = getService(SignalsServiceDefinition);
|
|
46
|
-
const categorySignal = signalsService.signal(config.category);
|
|
47
|
-
const isSelectedSignal = signalsService.signal(config.isSelected ?? false);
|
|
48
|
-
return {
|
|
49
|
-
category: categorySignal,
|
|
50
|
-
isSelected: isSelectedSignal,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
/**
|
|
54
|
-
* Loads category service configuration from the Wix Categories API for SSR initialization.
|
|
55
|
-
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
56
|
-
* a specific category by slug that will be used to configure the CategoryService.
|
|
57
|
-
*
|
|
58
|
-
* @param {string} slug - The category slug to load
|
|
59
|
-
* @returns {Promise} Promise that resolves to either success with config or not-found result
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```astro
|
|
63
|
-
* ---
|
|
64
|
-
* // Astro page example - pages/category/[slug].astro
|
|
65
|
-
* import { loadCategoryServiceConfig } from '@wix/stores/services';
|
|
66
|
-
* import { Category } from '@wix/stores/components/react';
|
|
67
|
-
*
|
|
68
|
-
* // Get category slug from URL params
|
|
69
|
-
* const { slug } = Astro.params;
|
|
70
|
-
*
|
|
71
|
-
* // Load category data during SSR
|
|
72
|
-
* const categoryResult = await loadCategoryServiceConfig(slug);
|
|
73
|
-
*
|
|
74
|
-
* // Handle not found case
|
|
75
|
-
* if (categoryResult.type === 'not-found') {
|
|
76
|
-
* return Astro.redirect('/404');
|
|
77
|
-
* }
|
|
78
|
-
* ---
|
|
79
|
-
*
|
|
80
|
-
* <Category.Root categoryConfig={categoryResult.config}>
|
|
81
|
-
* <Category.Name>
|
|
82
|
-
* {({ name }) => <h1>{name}</h1>}
|
|
83
|
-
* </Category.Name>
|
|
84
|
-
* </Category.Root>
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```tsx
|
|
89
|
-
* // Next.js page example - pages/category/[slug].tsx
|
|
90
|
-
* import { GetServerSideProps } from 'next';
|
|
91
|
-
* import { loadCategoryServiceConfig } from '@wix/stores/services';
|
|
92
|
-
* import { Category } from '@wix/stores/components/react';
|
|
93
|
-
*
|
|
94
|
-
* interface CategoryPageProps {
|
|
95
|
-
* categoryConfig: Awaited<ReturnType<typeof loadCategoryServiceConfig>>['config'];
|
|
96
|
-
* }
|
|
97
|
-
*
|
|
98
|
-
* export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async ({ params }) => {
|
|
99
|
-
* const slug = params?.slug as string;
|
|
100
|
-
*
|
|
101
|
-
* // Load category data during SSR
|
|
102
|
-
* const categoryResult = await loadCategoryServiceConfig(slug);
|
|
103
|
-
*
|
|
104
|
-
* // Handle not found case
|
|
105
|
-
* if (categoryResult.type === 'not-found') {
|
|
106
|
-
* return {
|
|
107
|
-
* notFound: true,
|
|
108
|
-
* };
|
|
109
|
-
* }
|
|
110
|
-
*
|
|
111
|
-
* return {
|
|
112
|
-
* props: {
|
|
113
|
-
* categoryConfig: categoryResult.config,
|
|
114
|
-
* },
|
|
115
|
-
* };
|
|
116
|
-
* };
|
|
117
|
-
*
|
|
118
|
-
* export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
|
|
119
|
-
* return (
|
|
120
|
-
* <Category.Root categoryConfig={categoryConfig}>
|
|
121
|
-
* <Category.Name>
|
|
122
|
-
* {({ name }) => <h1>{name}</h1>}
|
|
123
|
-
* </Category.Name>
|
|
124
|
-
* </Category.Root>
|
|
125
|
-
* );
|
|
126
|
-
* }
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
export async function loadCategoryServiceConfig(slug) {
|
|
130
|
-
const category = await categories
|
|
131
|
-
.queryCategories({
|
|
132
|
-
treeReference: {
|
|
133
|
-
appNamespace: '@wix/stores',
|
|
134
|
-
},
|
|
135
|
-
})
|
|
136
|
-
.eq('slug', slug)
|
|
137
|
-
.find();
|
|
138
|
-
if (category.items.length === 0) {
|
|
139
|
-
return {
|
|
140
|
-
type: 'not-found',
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
return {
|
|
144
|
-
type: 'success',
|
|
145
|
-
config: {
|
|
146
|
-
category: category.items[0],
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}
|