@wix/headless-stores 0.0.27 → 0.0.29
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/ProductsList.d.ts +29 -59
- package/cjs/dist/react/ProductsList.js +6 -37
- package/cjs/dist/services/products-list-service.d.ts +2 -2
- package/cjs/dist/services/products-list-service.js +1 -0
- package/dist/react/ProductsList.d.ts +29 -59
- package/dist/react/ProductsList.js +6 -37
- package/dist/services/products-list-service.d.ts +2 -2
- package/dist/services/products-list-service.js +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type ProductsListServiceConfig } from "../services/products-list-service.js";
|
|
2
|
-
import type { PropsWithChildren, ReactNode } from "react";
|
|
3
2
|
import { productsV3 } from "@wix/stores";
|
|
3
|
+
export interface RootProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
productsListConfig: ProductsListServiceConfig;
|
|
6
|
+
}
|
|
4
7
|
/**
|
|
5
8
|
* Root component that provides the ProductsList service context to its children.
|
|
6
9
|
* This component sets up the necessary services for managing products list state.
|
|
@@ -11,13 +14,12 @@ import { productsV3 } from "@wix/stores";
|
|
|
11
14
|
* @param props.productsListConfig - Configuration for the ProductsList service
|
|
12
15
|
* @returns JSX element wrapping children with ProductsList service context
|
|
13
16
|
*/
|
|
14
|
-
declare function Root(props:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export type EmptyStateRenderProps = {};
|
|
17
|
+
export declare function Root(props: RootProps): React.ReactNode;
|
|
18
|
+
export interface EmptyStateProps {
|
|
19
|
+
children: (props: EmptyStateRenderProps) => React.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export interface EmptyStateRenderProps {
|
|
22
|
+
}
|
|
21
23
|
/**
|
|
22
24
|
* Component that renders content when the products list is empty.
|
|
23
25
|
* Only displays its children when there are no products, no loading state, and no errors.
|
|
@@ -27,11 +29,12 @@ export type EmptyStateRenderProps = {};
|
|
|
27
29
|
* @param props.children - Content to display when products list is empty (can be a render function or ReactNode)
|
|
28
30
|
* @returns JSX element or null based on products list state
|
|
29
31
|
*/
|
|
30
|
-
declare function EmptyState(props: EmptyStateProps): ReactNode;
|
|
31
|
-
export
|
|
32
|
-
children: (
|
|
33
|
-
}
|
|
34
|
-
export
|
|
32
|
+
export declare function EmptyState(props: EmptyStateProps): React.ReactNode;
|
|
33
|
+
export interface LoadingProps {
|
|
34
|
+
children: (props: LoadingRenderProps) => React.ReactNode;
|
|
35
|
+
}
|
|
36
|
+
export interface LoadingRenderProps {
|
|
37
|
+
}
|
|
35
38
|
/**
|
|
36
39
|
* Component that renders content during loading state.
|
|
37
40
|
* Only displays its children when the products list is currently loading.
|
|
@@ -41,13 +44,13 @@ export type LoadingRenderProps = {};
|
|
|
41
44
|
* @param props.children - Content to display during loading (can be a render function or ReactNode)
|
|
42
45
|
* @returns JSX element or null based on loading state
|
|
43
46
|
*/
|
|
44
|
-
declare function Loading(props: LoadingProps): ReactNode;
|
|
45
|
-
export
|
|
46
|
-
children: ((props: ErrorRenderProps) => ReactNode) | ReactNode;
|
|
47
|
-
};
|
|
48
|
-
export type ErrorRenderProps = {
|
|
47
|
+
export declare function Loading(props: LoadingProps): React.ReactNode;
|
|
48
|
+
export interface ErrorRenderProps {
|
|
49
49
|
error: string | null;
|
|
50
|
-
}
|
|
50
|
+
}
|
|
51
|
+
export interface ErrorProps {
|
|
52
|
+
children: (props: ErrorRenderProps) => React.ReactNode;
|
|
53
|
+
}
|
|
51
54
|
/**
|
|
52
55
|
* Component that renders content when there's an error loading products.
|
|
53
56
|
* Only displays its children when an error has occurred.
|
|
@@ -57,13 +60,13 @@ export type ErrorRenderProps = {
|
|
|
57
60
|
* @param props.children - Content to display during error state (can be a render function or ReactNode)
|
|
58
61
|
* @returns JSX element or null based on error state
|
|
59
62
|
*/
|
|
60
|
-
declare function Error(props: ErrorProps): ReactNode;
|
|
61
|
-
export
|
|
63
|
+
export declare function Error(props: ErrorProps): React.ReactNode;
|
|
64
|
+
export interface ItemContentRenderProps {
|
|
62
65
|
product: productsV3.V3Product;
|
|
63
|
-
}
|
|
64
|
-
export
|
|
65
|
-
children: (
|
|
66
|
-
}
|
|
66
|
+
}
|
|
67
|
+
export interface ItemContentProps {
|
|
68
|
+
children: (props: ItemContentRenderProps) => React.ReactNode;
|
|
69
|
+
}
|
|
67
70
|
/**
|
|
68
71
|
* Component that renders content for each product in the list.
|
|
69
72
|
* Maps over all products and provides each product through a service context.
|
|
@@ -74,37 +77,4 @@ export type ItemContentProps = {
|
|
|
74
77
|
* @param props.children - Content to display for each product (can be a render function receiving product data or ReactNode)
|
|
75
78
|
* @returns Array of JSX elements for each product or null if no products to display
|
|
76
79
|
*/
|
|
77
|
-
declare function ItemContent(props: ItemContentProps):
|
|
78
|
-
/**
|
|
79
|
-
* ProductsList component collection providing a complete solution for displaying products.
|
|
80
|
-
*
|
|
81
|
-
* Includes components for different states:
|
|
82
|
-
* - Root: Service provider component
|
|
83
|
-
* - EmptyState: Displays when no products are available
|
|
84
|
-
* - Loading: Displays during loading state
|
|
85
|
-
* - Error: Displays when an error occurs
|
|
86
|
-
* - ItemContent: Renders individual product items
|
|
87
|
-
*
|
|
88
|
-
* @component
|
|
89
|
-
* @example
|
|
90
|
-
* ```jsx
|
|
91
|
-
* <ProductsList.Root productsListConfig={config}>
|
|
92
|
-
* <ProductsList.Loading>Loading products...</ProductsList.Loading>
|
|
93
|
-
* <ProductsList.Error>
|
|
94
|
-
* {({ error }) => <div>Error: {error}</div>}
|
|
95
|
-
* </ProductsList.Error>
|
|
96
|
-
* <ProductsList.EmptyState>No products found</ProductsList.EmptyState>
|
|
97
|
-
* <ProductsList.ItemContent>
|
|
98
|
-
* {({ product }) => <div>{product.name}</div>}
|
|
99
|
-
* </ProductsList.ItemContent>
|
|
100
|
-
* </ProductsList.Root>
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
export declare const ProductsList: {
|
|
104
|
-
Root: typeof Root;
|
|
105
|
-
EmptyState: typeof EmptyState;
|
|
106
|
-
Loading: typeof Loading;
|
|
107
|
-
Error: typeof Error;
|
|
108
|
-
ItemContent: typeof ItemContent;
|
|
109
|
-
};
|
|
110
|
-
export {};
|
|
80
|
+
export declare function ItemContent(props: ItemContentProps): React.ReactNode;
|
|
@@ -13,7 +13,7 @@ import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/
|
|
|
13
13
|
* @param props.productsListConfig - Configuration for the ProductsList service
|
|
14
14
|
* @returns JSX element wrapping children with ProductsList service context
|
|
15
15
|
*/
|
|
16
|
-
function Root(props) {
|
|
16
|
+
export function Root(props) {
|
|
17
17
|
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ProductsListServiceDefinition, ProductListService, props.productsListConfig), children: props.children }));
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -25,7 +25,7 @@ function Root(props) {
|
|
|
25
25
|
* @param props.children - Content to display when products list is empty (can be a render function or ReactNode)
|
|
26
26
|
* @returns JSX element or null based on products list state
|
|
27
27
|
*/
|
|
28
|
-
function EmptyState(props) {
|
|
28
|
+
export function EmptyState(props) {
|
|
29
29
|
const { isLoading, error, products } = useService(ProductsListServiceDefinition);
|
|
30
30
|
const isLoadingValue = isLoading.get();
|
|
31
31
|
const errorValue = error.get();
|
|
@@ -46,7 +46,7 @@ function EmptyState(props) {
|
|
|
46
46
|
* @param props.children - Content to display during loading (can be a render function or ReactNode)
|
|
47
47
|
* @returns JSX element or null based on loading state
|
|
48
48
|
*/
|
|
49
|
-
function Loading(props) {
|
|
49
|
+
export function Loading(props) {
|
|
50
50
|
const { isLoading } = useService(ProductsListServiceDefinition);
|
|
51
51
|
const isLoadingValue = isLoading.get();
|
|
52
52
|
if (isLoadingValue) {
|
|
@@ -56,6 +56,7 @@ function Loading(props) {
|
|
|
56
56
|
}
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
|
+
;
|
|
59
60
|
/**
|
|
60
61
|
* Component that renders content when there's an error loading products.
|
|
61
62
|
* Only displays its children when an error has occurred.
|
|
@@ -65,7 +66,7 @@ function Loading(props) {
|
|
|
65
66
|
* @param props.children - Content to display during error state (can be a render function or ReactNode)
|
|
66
67
|
* @returns JSX element or null based on error state
|
|
67
68
|
*/
|
|
68
|
-
function Error(props) {
|
|
69
|
+
export function Error(props) {
|
|
69
70
|
const { error } = useService(ProductsListServiceDefinition);
|
|
70
71
|
const errorValue = error.get();
|
|
71
72
|
if (errorValue) {
|
|
@@ -85,7 +86,7 @@ function Error(props) {
|
|
|
85
86
|
* @param props.children - Content to display for each product (can be a render function receiving product data or ReactNode)
|
|
86
87
|
* @returns Array of JSX elements for each product or null if no products to display
|
|
87
88
|
*/
|
|
88
|
-
function ItemContent(props) {
|
|
89
|
+
export function ItemContent(props) {
|
|
89
90
|
const { products, isLoading, error } = useService(ProductsListServiceDefinition);
|
|
90
91
|
const productsValue = products.get();
|
|
91
92
|
if (isLoading.get() || error.get() || productsValue.length === 0) {
|
|
@@ -95,35 +96,3 @@ function ItemContent(props) {
|
|
|
95
96
|
? props.children({ product })
|
|
96
97
|
: props.children }, product._id)));
|
|
97
98
|
}
|
|
98
|
-
/**
|
|
99
|
-
* ProductsList component collection providing a complete solution for displaying products.
|
|
100
|
-
*
|
|
101
|
-
* Includes components for different states:
|
|
102
|
-
* - Root: Service provider component
|
|
103
|
-
* - EmptyState: Displays when no products are available
|
|
104
|
-
* - Loading: Displays during loading state
|
|
105
|
-
* - Error: Displays when an error occurs
|
|
106
|
-
* - ItemContent: Renders individual product items
|
|
107
|
-
*
|
|
108
|
-
* @component
|
|
109
|
-
* @example
|
|
110
|
-
* ```jsx
|
|
111
|
-
* <ProductsList.Root productsListConfig={config}>
|
|
112
|
-
* <ProductsList.Loading>Loading products...</ProductsList.Loading>
|
|
113
|
-
* <ProductsList.Error>
|
|
114
|
-
* {({ error }) => <div>Error: {error}</div>}
|
|
115
|
-
* </ProductsList.Error>
|
|
116
|
-
* <ProductsList.EmptyState>No products found</ProductsList.EmptyState>
|
|
117
|
-
* <ProductsList.ItemContent>
|
|
118
|
-
* {({ product }) => <div>{product.name}</div>}
|
|
119
|
-
* </ProductsList.ItemContent>
|
|
120
|
-
* </ProductsList.Root>
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
export const ProductsList = {
|
|
124
|
-
Root,
|
|
125
|
-
EmptyState,
|
|
126
|
-
Loading,
|
|
127
|
-
Error,
|
|
128
|
-
ItemContent,
|
|
129
|
-
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
2
|
import { productsV3 } from "@wix/stores";
|
|
3
|
-
export
|
|
3
|
+
export interface ProductsListServiceConfig {
|
|
4
4
|
products: productsV3.V3Product[];
|
|
5
5
|
searchOptions: Parameters<typeof productsV3.searchProducts>[0];
|
|
6
6
|
pagingMetadata: productsV3.CommonCursorPagingMetadata;
|
|
7
7
|
aggregations: productsV3.AggregationData;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
export declare function loadProductsListServiceConfig(searchOptions: Parameters<typeof productsV3.searchProducts>[0]): Promise<ProductsListServiceConfig>;
|
|
10
10
|
export declare const ProductsListServiceDefinition: string & {
|
|
11
11
|
__api: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
2
|
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
3
|
import { productsV3 } from "@wix/stores";
|
|
4
|
+
;
|
|
4
5
|
export async function loadProductsListServiceConfig(searchOptions) {
|
|
5
6
|
const result = await productsV3.searchProducts(searchOptions);
|
|
6
7
|
return {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type ProductsListServiceConfig } from "../services/products-list-service.js";
|
|
2
|
-
import type { PropsWithChildren, ReactNode } from "react";
|
|
3
2
|
import { productsV3 } from "@wix/stores";
|
|
3
|
+
export interface RootProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
productsListConfig: ProductsListServiceConfig;
|
|
6
|
+
}
|
|
4
7
|
/**
|
|
5
8
|
* Root component that provides the ProductsList service context to its children.
|
|
6
9
|
* This component sets up the necessary services for managing products list state.
|
|
@@ -11,13 +14,12 @@ import { productsV3 } from "@wix/stores";
|
|
|
11
14
|
* @param props.productsListConfig - Configuration for the ProductsList service
|
|
12
15
|
* @returns JSX element wrapping children with ProductsList service context
|
|
13
16
|
*/
|
|
14
|
-
declare function Root(props:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export type EmptyStateRenderProps = {};
|
|
17
|
+
export declare function Root(props: RootProps): React.ReactNode;
|
|
18
|
+
export interface EmptyStateProps {
|
|
19
|
+
children: (props: EmptyStateRenderProps) => React.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export interface EmptyStateRenderProps {
|
|
22
|
+
}
|
|
21
23
|
/**
|
|
22
24
|
* Component that renders content when the products list is empty.
|
|
23
25
|
* Only displays its children when there are no products, no loading state, and no errors.
|
|
@@ -27,11 +29,12 @@ export type EmptyStateRenderProps = {};
|
|
|
27
29
|
* @param props.children - Content to display when products list is empty (can be a render function or ReactNode)
|
|
28
30
|
* @returns JSX element or null based on products list state
|
|
29
31
|
*/
|
|
30
|
-
declare function EmptyState(props: EmptyStateProps): ReactNode;
|
|
31
|
-
export
|
|
32
|
-
children: (
|
|
33
|
-
}
|
|
34
|
-
export
|
|
32
|
+
export declare function EmptyState(props: EmptyStateProps): React.ReactNode;
|
|
33
|
+
export interface LoadingProps {
|
|
34
|
+
children: (props: LoadingRenderProps) => React.ReactNode;
|
|
35
|
+
}
|
|
36
|
+
export interface LoadingRenderProps {
|
|
37
|
+
}
|
|
35
38
|
/**
|
|
36
39
|
* Component that renders content during loading state.
|
|
37
40
|
* Only displays its children when the products list is currently loading.
|
|
@@ -41,13 +44,13 @@ export type LoadingRenderProps = {};
|
|
|
41
44
|
* @param props.children - Content to display during loading (can be a render function or ReactNode)
|
|
42
45
|
* @returns JSX element or null based on loading state
|
|
43
46
|
*/
|
|
44
|
-
declare function Loading(props: LoadingProps): ReactNode;
|
|
45
|
-
export
|
|
46
|
-
children: ((props: ErrorRenderProps) => ReactNode) | ReactNode;
|
|
47
|
-
};
|
|
48
|
-
export type ErrorRenderProps = {
|
|
47
|
+
export declare function Loading(props: LoadingProps): React.ReactNode;
|
|
48
|
+
export interface ErrorRenderProps {
|
|
49
49
|
error: string | null;
|
|
50
|
-
}
|
|
50
|
+
}
|
|
51
|
+
export interface ErrorProps {
|
|
52
|
+
children: (props: ErrorRenderProps) => React.ReactNode;
|
|
53
|
+
}
|
|
51
54
|
/**
|
|
52
55
|
* Component that renders content when there's an error loading products.
|
|
53
56
|
* Only displays its children when an error has occurred.
|
|
@@ -57,13 +60,13 @@ export type ErrorRenderProps = {
|
|
|
57
60
|
* @param props.children - Content to display during error state (can be a render function or ReactNode)
|
|
58
61
|
* @returns JSX element or null based on error state
|
|
59
62
|
*/
|
|
60
|
-
declare function Error(props: ErrorProps): ReactNode;
|
|
61
|
-
export
|
|
63
|
+
export declare function Error(props: ErrorProps): React.ReactNode;
|
|
64
|
+
export interface ItemContentRenderProps {
|
|
62
65
|
product: productsV3.V3Product;
|
|
63
|
-
}
|
|
64
|
-
export
|
|
65
|
-
children: (
|
|
66
|
-
}
|
|
66
|
+
}
|
|
67
|
+
export interface ItemContentProps {
|
|
68
|
+
children: (props: ItemContentRenderProps) => React.ReactNode;
|
|
69
|
+
}
|
|
67
70
|
/**
|
|
68
71
|
* Component that renders content for each product in the list.
|
|
69
72
|
* Maps over all products and provides each product through a service context.
|
|
@@ -74,37 +77,4 @@ export type ItemContentProps = {
|
|
|
74
77
|
* @param props.children - Content to display for each product (can be a render function receiving product data or ReactNode)
|
|
75
78
|
* @returns Array of JSX elements for each product or null if no products to display
|
|
76
79
|
*/
|
|
77
|
-
declare function ItemContent(props: ItemContentProps):
|
|
78
|
-
/**
|
|
79
|
-
* ProductsList component collection providing a complete solution for displaying products.
|
|
80
|
-
*
|
|
81
|
-
* Includes components for different states:
|
|
82
|
-
* - Root: Service provider component
|
|
83
|
-
* - EmptyState: Displays when no products are available
|
|
84
|
-
* - Loading: Displays during loading state
|
|
85
|
-
* - Error: Displays when an error occurs
|
|
86
|
-
* - ItemContent: Renders individual product items
|
|
87
|
-
*
|
|
88
|
-
* @component
|
|
89
|
-
* @example
|
|
90
|
-
* ```jsx
|
|
91
|
-
* <ProductsList.Root productsListConfig={config}>
|
|
92
|
-
* <ProductsList.Loading>Loading products...</ProductsList.Loading>
|
|
93
|
-
* <ProductsList.Error>
|
|
94
|
-
* {({ error }) => <div>Error: {error}</div>}
|
|
95
|
-
* </ProductsList.Error>
|
|
96
|
-
* <ProductsList.EmptyState>No products found</ProductsList.EmptyState>
|
|
97
|
-
* <ProductsList.ItemContent>
|
|
98
|
-
* {({ product }) => <div>{product.name}</div>}
|
|
99
|
-
* </ProductsList.ItemContent>
|
|
100
|
-
* </ProductsList.Root>
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
export declare const ProductsList: {
|
|
104
|
-
Root: typeof Root;
|
|
105
|
-
EmptyState: typeof EmptyState;
|
|
106
|
-
Loading: typeof Loading;
|
|
107
|
-
Error: typeof Error;
|
|
108
|
-
ItemContent: typeof ItemContent;
|
|
109
|
-
};
|
|
110
|
-
export {};
|
|
80
|
+
export declare function ItemContent(props: ItemContentProps): React.ReactNode;
|
|
@@ -13,7 +13,7 @@ import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/
|
|
|
13
13
|
* @param props.productsListConfig - Configuration for the ProductsList service
|
|
14
14
|
* @returns JSX element wrapping children with ProductsList service context
|
|
15
15
|
*/
|
|
16
|
-
function Root(props) {
|
|
16
|
+
export function Root(props) {
|
|
17
17
|
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ProductsListServiceDefinition, ProductListService, props.productsListConfig), children: props.children }));
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -25,7 +25,7 @@ function Root(props) {
|
|
|
25
25
|
* @param props.children - Content to display when products list is empty (can be a render function or ReactNode)
|
|
26
26
|
* @returns JSX element or null based on products list state
|
|
27
27
|
*/
|
|
28
|
-
function EmptyState(props) {
|
|
28
|
+
export function EmptyState(props) {
|
|
29
29
|
const { isLoading, error, products } = useService(ProductsListServiceDefinition);
|
|
30
30
|
const isLoadingValue = isLoading.get();
|
|
31
31
|
const errorValue = error.get();
|
|
@@ -46,7 +46,7 @@ function EmptyState(props) {
|
|
|
46
46
|
* @param props.children - Content to display during loading (can be a render function or ReactNode)
|
|
47
47
|
* @returns JSX element or null based on loading state
|
|
48
48
|
*/
|
|
49
|
-
function Loading(props) {
|
|
49
|
+
export function Loading(props) {
|
|
50
50
|
const { isLoading } = useService(ProductsListServiceDefinition);
|
|
51
51
|
const isLoadingValue = isLoading.get();
|
|
52
52
|
if (isLoadingValue) {
|
|
@@ -56,6 +56,7 @@ function Loading(props) {
|
|
|
56
56
|
}
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
|
+
;
|
|
59
60
|
/**
|
|
60
61
|
* Component that renders content when there's an error loading products.
|
|
61
62
|
* Only displays its children when an error has occurred.
|
|
@@ -65,7 +66,7 @@ function Loading(props) {
|
|
|
65
66
|
* @param props.children - Content to display during error state (can be a render function or ReactNode)
|
|
66
67
|
* @returns JSX element or null based on error state
|
|
67
68
|
*/
|
|
68
|
-
function Error(props) {
|
|
69
|
+
export function Error(props) {
|
|
69
70
|
const { error } = useService(ProductsListServiceDefinition);
|
|
70
71
|
const errorValue = error.get();
|
|
71
72
|
if (errorValue) {
|
|
@@ -85,7 +86,7 @@ function Error(props) {
|
|
|
85
86
|
* @param props.children - Content to display for each product (can be a render function receiving product data or ReactNode)
|
|
86
87
|
* @returns Array of JSX elements for each product or null if no products to display
|
|
87
88
|
*/
|
|
88
|
-
function ItemContent(props) {
|
|
89
|
+
export function ItemContent(props) {
|
|
89
90
|
const { products, isLoading, error } = useService(ProductsListServiceDefinition);
|
|
90
91
|
const productsValue = products.get();
|
|
91
92
|
if (isLoading.get() || error.get() || productsValue.length === 0) {
|
|
@@ -95,35 +96,3 @@ function ItemContent(props) {
|
|
|
95
96
|
? props.children({ product })
|
|
96
97
|
: props.children }, product._id)));
|
|
97
98
|
}
|
|
98
|
-
/**
|
|
99
|
-
* ProductsList component collection providing a complete solution for displaying products.
|
|
100
|
-
*
|
|
101
|
-
* Includes components for different states:
|
|
102
|
-
* - Root: Service provider component
|
|
103
|
-
* - EmptyState: Displays when no products are available
|
|
104
|
-
* - Loading: Displays during loading state
|
|
105
|
-
* - Error: Displays when an error occurs
|
|
106
|
-
* - ItemContent: Renders individual product items
|
|
107
|
-
*
|
|
108
|
-
* @component
|
|
109
|
-
* @example
|
|
110
|
-
* ```jsx
|
|
111
|
-
* <ProductsList.Root productsListConfig={config}>
|
|
112
|
-
* <ProductsList.Loading>Loading products...</ProductsList.Loading>
|
|
113
|
-
* <ProductsList.Error>
|
|
114
|
-
* {({ error }) => <div>Error: {error}</div>}
|
|
115
|
-
* </ProductsList.Error>
|
|
116
|
-
* <ProductsList.EmptyState>No products found</ProductsList.EmptyState>
|
|
117
|
-
* <ProductsList.ItemContent>
|
|
118
|
-
* {({ product }) => <div>{product.name}</div>}
|
|
119
|
-
* </ProductsList.ItemContent>
|
|
120
|
-
* </ProductsList.Root>
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
export const ProductsList = {
|
|
124
|
-
Root,
|
|
125
|
-
EmptyState,
|
|
126
|
-
Loading,
|
|
127
|
-
Error,
|
|
128
|
-
ItemContent,
|
|
129
|
-
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
2
|
import { productsV3 } from "@wix/stores";
|
|
3
|
-
export
|
|
3
|
+
export interface ProductsListServiceConfig {
|
|
4
4
|
products: productsV3.V3Product[];
|
|
5
5
|
searchOptions: Parameters<typeof productsV3.searchProducts>[0];
|
|
6
6
|
pagingMetadata: productsV3.CommonCursorPagingMetadata;
|
|
7
7
|
aggregations: productsV3.AggregationData;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
export declare function loadProductsListServiceConfig(searchOptions: Parameters<typeof productsV3.searchProducts>[0]): Promise<ProductsListServiceConfig>;
|
|
10
10
|
export declare const ProductsListServiceDefinition: string & {
|
|
11
11
|
__api: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
2
|
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
3
|
import { productsV3 } from "@wix/stores";
|
|
4
|
+
;
|
|
4
5
|
export async function loadProductsListServiceConfig(searchOptions) {
|
|
5
6
|
const result = await productsV3.searchProducts(searchOptions);
|
|
6
7
|
return {
|