@shopify/shop-minis-react 0.0.10 → 0.0.12
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/dist/_virtual/debounce.js +8 -0
- package/dist/_virtual/debounce.js.map +1 -0
- package/dist/components/commerce/merchant-card.js +201 -0
- package/dist/components/commerce/merchant-card.js.map +1 -0
- package/dist/components/commerce/product-card.js +11 -9
- package/dist/components/commerce/product-card.js.map +1 -1
- package/dist/hooks/product/useCuratedProducts.js +20 -0
- package/dist/hooks/product/useCuratedProducts.js.map +1 -0
- package/dist/hooks/product/useProduct.js +24 -0
- package/dist/hooks/product/useProduct.js.map +1 -0
- package/dist/hooks/product/useProductMedia.js +24 -0
- package/dist/hooks/product/useProductMedia.js.map +1 -0
- package/dist/hooks/product/useProductSearch.js +44 -0
- package/dist/hooks/product/useProductSearch.js.map +1 -0
- package/dist/hooks/product/useProductVariants.js +21 -0
- package/dist/hooks/product/useProductVariants.js.map +1 -0
- package/dist/hooks/product/useProducts.js +17 -0
- package/dist/hooks/product/useProducts.js.map +1 -0
- package/dist/hooks/shop/useShop.js +17 -0
- package/dist/hooks/shop/useShop.js.map +1 -0
- package/dist/hooks/user/useFollowedShops.js +21 -0
- package/dist/hooks/user/useFollowedShops.js.map +1 -0
- package/dist/hooks/user/useRecentProducts.js +21 -0
- package/dist/hooks/user/useRecentProducts.js.map +1 -0
- package/dist/hooks/user/useRecentShops.js +21 -0
- package/dist/hooks/user/useRecentShops.js.map +1 -0
- package/dist/hooks/user/useSavedProducts.js +21 -0
- package/dist/hooks/user/useSavedProducts.js.map +1 -0
- package/dist/index.js +210 -178
- package/dist/index.js.map +1 -1
- package/dist/internal/useShopActionsPaginatedDataFetching.js +24 -24
- package/dist/internal/useShopActionsPaginatedDataFetching.js.map +1 -1
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Symbol.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Symbol.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseTrim.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseTrim.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getRawTag.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getRawTag.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_objectToString.js +14 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_objectToString.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_trimmedEndIndex.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_trimmedEndIndex.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/debounce.js +61 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/debounce.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObject.js +14 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObject.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObjectLike.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObjectLike.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isSymbol.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isSymbol.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/now.js +14 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/now.js.map +1 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/toNumber.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/toNumber.js.map +1 -0
- package/dist/types/minisSDK.generated.d.js.map +1 -1
- package/package.json +18 -17
- package/src/base.css +264 -0
- package/src/components/commerce/merchant-card.tsx +262 -0
- package/src/components/commerce/product-card.tsx +3 -1
- package/src/components/index.ts +1 -0
- package/src/hooks/index.ts +11 -0
- package/src/hooks/product/useCuratedProducts.doc.ts +32 -0
- package/src/hooks/product/useCuratedProducts.example.tsx +10 -0
- package/src/hooks/product/useCuratedProducts.ts +41 -0
- package/src/hooks/product/useProduct.ts +45 -0
- package/src/hooks/product/useProductMedia.ts +51 -0
- package/src/hooks/product/useProductSearch.doc.ts +32 -0
- package/src/hooks/product/useProductSearch.example.tsx +13 -0
- package/src/hooks/product/useProductSearch.ts +95 -0
- package/src/hooks/product/useProductVariants.ts +48 -0
- package/src/hooks/product/useProducts.ts +38 -0
- package/src/hooks/shop/useShop.doc.ts +31 -0
- package/src/hooks/shop/useShop.example.tsx +7 -0
- package/src/hooks/shop/useShop.ts +38 -0
- package/src/hooks/user/useFollowedShops.ts +43 -0
- package/src/hooks/user/useRecentProducts.doc.ts +32 -0
- package/src/hooks/user/useRecentProducts.example.tsx +13 -0
- package/src/hooks/user/useRecentProducts.ts +46 -0
- package/src/hooks/user/useRecentShops.ts +43 -0
- package/src/hooks/user/useSavedProducts.doc.ts +32 -0
- package/src/hooks/user/useSavedProducts.example.tsx +13 -0
- package/src/hooks/user/useSavedProducts.ts +46 -0
- package/src/index.css +1 -221
- package/src/internal/useShopActionsPaginatedDataFetching.ts +8 -8
- package/src/types/minisSDK.generated.d.ts +239 -4
- package/src/dev.tsx +0 -868
- package/src/mockActions.ts +0 -237
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
2
|
+
import {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'
|
|
3
|
+
import {
|
|
4
|
+
Product,
|
|
5
|
+
PaginatedDataHookOptionsBase,
|
|
6
|
+
PaginatedDataHookReturnsBase,
|
|
7
|
+
} from '../../types'
|
|
8
|
+
|
|
9
|
+
interface UseCuratedProductsParams extends PaginatedDataHookOptionsBase {
|
|
10
|
+
handle: string
|
|
11
|
+
requiredTags?: string[]
|
|
12
|
+
anyOfTags?: string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface UseCuratedProductsReturns extends PaginatedDataHookReturnsBase {
|
|
16
|
+
products: Product[] | null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param options - The options for the query
|
|
21
|
+
*/
|
|
22
|
+
export const useCuratedProducts = (
|
|
23
|
+
params: UseCuratedProductsParams
|
|
24
|
+
): UseCuratedProductsReturns => {
|
|
25
|
+
const {getCuratedProducts} = useShopActions()
|
|
26
|
+
const {skip, ...shopActionParams} = params ?? {}
|
|
27
|
+
|
|
28
|
+
const {data, ...rest} = useShopActionsPaginatedDataFetching(
|
|
29
|
+
getCuratedProducts,
|
|
30
|
+
shopActionParams,
|
|
31
|
+
{
|
|
32
|
+
skip,
|
|
33
|
+
hook: 'useCuratedProducts',
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
...rest,
|
|
39
|
+
products: data,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
4
|
+
import {useShopActionsDataFetching} from '../../internal/useShopActionsDataFetching'
|
|
5
|
+
import {DataHookOptionsBase, DataHookReturnsBase, Product} from '../../types'
|
|
6
|
+
|
|
7
|
+
export interface UseProductParams extends DataHookOptionsBase {
|
|
8
|
+
/**
|
|
9
|
+
* The product ID to fetch.
|
|
10
|
+
*/
|
|
11
|
+
id: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface UseProductReturns extends DataHookReturnsBase {
|
|
15
|
+
/**
|
|
16
|
+
* The product returned from the query.
|
|
17
|
+
*/
|
|
18
|
+
product: Product | null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const useProduct = (params: UseProductParams): UseProductReturns => {
|
|
22
|
+
const {getProduct} = useShopActions()
|
|
23
|
+
const {id, skip = false, ...restParams} = params
|
|
24
|
+
|
|
25
|
+
const {data, ...rest} = useShopActionsDataFetching(
|
|
26
|
+
getProduct,
|
|
27
|
+
{
|
|
28
|
+
id,
|
|
29
|
+
...restParams,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
skip,
|
|
33
|
+
hook: 'useProduct',
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
const product = useMemo(() => {
|
|
38
|
+
return data ?? null
|
|
39
|
+
}, [data])
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
...rest,
|
|
43
|
+
product,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
4
|
+
import {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'
|
|
5
|
+
import {
|
|
6
|
+
PaginatedDataHookOptionsBase,
|
|
7
|
+
PaginatedDataHookReturnsBase,
|
|
8
|
+
ProductMedia,
|
|
9
|
+
} from '../../types'
|
|
10
|
+
|
|
11
|
+
export interface UseProductMediaParams extends PaginatedDataHookOptionsBase {
|
|
12
|
+
/**
|
|
13
|
+
* The product ID to fetch media for.
|
|
14
|
+
*/
|
|
15
|
+
id: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface UseProductMediaReturns extends PaginatedDataHookReturnsBase {
|
|
19
|
+
/**
|
|
20
|
+
* The product media returned from the query.
|
|
21
|
+
*/
|
|
22
|
+
media: ProductMedia[] | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const useProductMedia = (
|
|
26
|
+
params: UseProductMediaParams
|
|
27
|
+
): UseProductMediaReturns => {
|
|
28
|
+
const {getProductMedia} = useShopActions()
|
|
29
|
+
const {id, skip = false, ...restParams} = params
|
|
30
|
+
|
|
31
|
+
const {data, ...rest} = useShopActionsPaginatedDataFetching(
|
|
32
|
+
getProductMedia,
|
|
33
|
+
{
|
|
34
|
+
id,
|
|
35
|
+
...restParams,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
skip,
|
|
39
|
+
hook: 'useProductMedia',
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const media = useMemo(() => {
|
|
44
|
+
return data ?? null
|
|
45
|
+
}, [data])
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
...rest,
|
|
49
|
+
media,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'
|
|
2
|
+
|
|
3
|
+
const data: ReferenceEntityTemplateSchema = {
|
|
4
|
+
name: 'useProductSearch',
|
|
5
|
+
category: 'hooks',
|
|
6
|
+
subCategory: 'product',
|
|
7
|
+
isVisualComponent: false,
|
|
8
|
+
related: [],
|
|
9
|
+
description:
|
|
10
|
+
'The `useProductSearch` hook fetches products based on a search query.',
|
|
11
|
+
type: 'hook',
|
|
12
|
+
defaultExample: {
|
|
13
|
+
codeblock: {
|
|
14
|
+
tabs: [
|
|
15
|
+
{
|
|
16
|
+
code: './useProductSearch.example.tsx',
|
|
17
|
+
language: 'tsx',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
title: 'Example code',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
definitions: [
|
|
24
|
+
{
|
|
25
|
+
title: '',
|
|
26
|
+
type: 'UseProductSearchGeneratedType',
|
|
27
|
+
description: '',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default data
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {useProductSearch} from '@shopify/shop-minis-react'
|
|
2
|
+
|
|
3
|
+
export default function MyComponent() {
|
|
4
|
+
const {products, loading} = useProductSearch({
|
|
5
|
+
query: 'shirt',
|
|
6
|
+
first: 10,
|
|
7
|
+
filters: {
|
|
8
|
+
color: ['RED'],
|
|
9
|
+
},
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
console.log({products, loading})
|
|
13
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {useCallback, useEffect, useMemo, useState} from 'react'
|
|
2
|
+
|
|
3
|
+
import debounce from 'lodash/debounce'
|
|
4
|
+
|
|
5
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
6
|
+
import {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'
|
|
7
|
+
import {
|
|
8
|
+
PaginatedDataHookOptionsBase,
|
|
9
|
+
PaginatedDataHookReturnsBase,
|
|
10
|
+
Product,
|
|
11
|
+
ProductFilters,
|
|
12
|
+
ProductSearchSortBy,
|
|
13
|
+
} from '../../types'
|
|
14
|
+
|
|
15
|
+
export interface UseProductSearchParams extends PaginatedDataHookOptionsBase {
|
|
16
|
+
/**
|
|
17
|
+
* The search query.
|
|
18
|
+
*/
|
|
19
|
+
query: string
|
|
20
|
+
/**
|
|
21
|
+
* The filters to apply to the search.
|
|
22
|
+
*/
|
|
23
|
+
filters?: ProductFilters
|
|
24
|
+
/**
|
|
25
|
+
* The sort order of the results.
|
|
26
|
+
*/
|
|
27
|
+
sortBy?: ProductSearchSortBy
|
|
28
|
+
/**
|
|
29
|
+
* Whether to include sensitive products.
|
|
30
|
+
*/
|
|
31
|
+
includeSensitive?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface UseProductSearchReturns extends PaginatedDataHookReturnsBase {
|
|
35
|
+
/**
|
|
36
|
+
* The products returned from the query.
|
|
37
|
+
*/
|
|
38
|
+
products: Product[] | null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const useProductSearch = (
|
|
42
|
+
params: UseProductSearchParams
|
|
43
|
+
): UseProductSearchReturns => {
|
|
44
|
+
const {getProductSearch} = useShopActions()
|
|
45
|
+
const {
|
|
46
|
+
query,
|
|
47
|
+
filters,
|
|
48
|
+
sortBy,
|
|
49
|
+
includeSensitive = false,
|
|
50
|
+
skip = false,
|
|
51
|
+
...restParams
|
|
52
|
+
} = params ?? {}
|
|
53
|
+
|
|
54
|
+
const [debouncedQuery, setDebouncedQuery] = useState<string>(query)
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
+
const debouncedSetQuery = useCallback(
|
|
58
|
+
debounce((newQuery: string) => {
|
|
59
|
+
setDebouncedQuery(newQuery)
|
|
60
|
+
}, 300),
|
|
61
|
+
[]
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
debouncedSetQuery(query)
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
debouncedSetQuery.cancel()
|
|
69
|
+
}
|
|
70
|
+
}, [query, debouncedSetQuery])
|
|
71
|
+
|
|
72
|
+
const {data, ...rest} = useShopActionsPaginatedDataFetching(
|
|
73
|
+
getProductSearch,
|
|
74
|
+
{
|
|
75
|
+
query: debouncedQuery,
|
|
76
|
+
filters,
|
|
77
|
+
sortBy,
|
|
78
|
+
includeSensitive,
|
|
79
|
+
...restParams,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
skip,
|
|
83
|
+
hook: 'useProductSearch',
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
const products = useMemo(() => {
|
|
88
|
+
return data ?? null
|
|
89
|
+
}, [data])
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
...rest,
|
|
93
|
+
products,
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
4
|
+
import {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'
|
|
5
|
+
import {
|
|
6
|
+
PaginatedDataHookOptionsBase,
|
|
7
|
+
PaginatedDataHookReturnsBase,
|
|
8
|
+
ProductVariant,
|
|
9
|
+
} from '../../types'
|
|
10
|
+
|
|
11
|
+
export interface UseProductVariantsParams extends PaginatedDataHookOptionsBase {
|
|
12
|
+
/**
|
|
13
|
+
* The product ID to fetch variants for.
|
|
14
|
+
*/
|
|
15
|
+
id: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface UseProductVariantsReturns extends PaginatedDataHookReturnsBase {
|
|
19
|
+
/**
|
|
20
|
+
* The product variants returned from the query.
|
|
21
|
+
*/
|
|
22
|
+
variants: ProductVariant[] | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const useProductVariants = (
|
|
26
|
+
params: UseProductVariantsParams
|
|
27
|
+
): UseProductVariantsReturns => {
|
|
28
|
+
const {getProductVariants} = useShopActions()
|
|
29
|
+
const {skip = false, ...restParams} = params
|
|
30
|
+
|
|
31
|
+
const {data, ...rest} = useShopActionsPaginatedDataFetching(
|
|
32
|
+
getProductVariants,
|
|
33
|
+
restParams,
|
|
34
|
+
{
|
|
35
|
+
skip,
|
|
36
|
+
hook: 'useProductVariants',
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const variants = useMemo(() => {
|
|
41
|
+
return data ?? null
|
|
42
|
+
}, [data])
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
...rest,
|
|
46
|
+
variants,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
4
|
+
import {useShopActionsDataFetching} from '../../internal/useShopActionsDataFetching'
|
|
5
|
+
import {DataHookOptionsBase, DataHookReturnsBase, Product} from '../../types'
|
|
6
|
+
|
|
7
|
+
export interface UseProductsParams extends DataHookOptionsBase {
|
|
8
|
+
/**
|
|
9
|
+
* The product IDs to fetch.
|
|
10
|
+
*/
|
|
11
|
+
ids: string[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface UseProductsReturns extends DataHookReturnsBase {
|
|
15
|
+
/**
|
|
16
|
+
* The products returned from the query.
|
|
17
|
+
*/
|
|
18
|
+
products: Product[] | null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const useProducts = (params: UseProductsParams): UseProductsReturns => {
|
|
22
|
+
const {getProducts} = useShopActions()
|
|
23
|
+
const {skip = false, ...restParams} = params
|
|
24
|
+
|
|
25
|
+
const {data, ...rest} = useShopActionsDataFetching(getProducts, restParams, {
|
|
26
|
+
skip,
|
|
27
|
+
hook: 'useProducts',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const products = useMemo(() => {
|
|
31
|
+
return data ?? null
|
|
32
|
+
}, [data])
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
...rest,
|
|
36
|
+
products,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'
|
|
2
|
+
|
|
3
|
+
const data: ReferenceEntityTemplateSchema = {
|
|
4
|
+
name: 'useShop',
|
|
5
|
+
category: 'hooks',
|
|
6
|
+
subCategory: 'shop',
|
|
7
|
+
isVisualComponent: false,
|
|
8
|
+
related: [],
|
|
9
|
+
description: 'The `useShop` hook enables fetching a shop by its ID.',
|
|
10
|
+
type: 'hook',
|
|
11
|
+
defaultExample: {
|
|
12
|
+
codeblock: {
|
|
13
|
+
tabs: [
|
|
14
|
+
{
|
|
15
|
+
code: './useShop.example.tsx',
|
|
16
|
+
language: 'tsx',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
title: 'Example code',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
definitions: [
|
|
23
|
+
{
|
|
24
|
+
title: '',
|
|
25
|
+
type: 'UseShopGeneratedType',
|
|
26
|
+
description: '',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default data
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
4
|
+
import {useShopActionsDataFetching} from '../../internal/useShopActionsDataFetching'
|
|
5
|
+
import {DataHookOptionsBase, DataHookReturnsBase, Shop} from '../../types'
|
|
6
|
+
|
|
7
|
+
export interface UseShopParams extends DataHookOptionsBase {
|
|
8
|
+
/**
|
|
9
|
+
* The shop ID to fetch.
|
|
10
|
+
*/
|
|
11
|
+
id: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface UseShopReturns extends DataHookReturnsBase {
|
|
15
|
+
/**
|
|
16
|
+
* The shop returned from the query.
|
|
17
|
+
*/
|
|
18
|
+
shop: Shop | null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const useShop = (params: UseShopParams): UseShopReturns => {
|
|
22
|
+
const {getShop} = useShopActions()
|
|
23
|
+
const {skip = false, ...restParams} = params
|
|
24
|
+
|
|
25
|
+
const {data, ...rest} = useShopActionsDataFetching(getShop, restParams, {
|
|
26
|
+
skip,
|
|
27
|
+
hook: 'useShop',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const shop = useMemo(() => {
|
|
31
|
+
return data ?? null
|
|
32
|
+
}, [data])
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
...rest,
|
|
36
|
+
shop,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
4
|
+
import {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'
|
|
5
|
+
import {
|
|
6
|
+
PaginatedDataHookOptionsBase,
|
|
7
|
+
PaginatedDataHookReturnsBase,
|
|
8
|
+
Shop,
|
|
9
|
+
} from '../../types'
|
|
10
|
+
|
|
11
|
+
export interface UseFollowedShopsParams extends PaginatedDataHookOptionsBase {}
|
|
12
|
+
|
|
13
|
+
interface UseFollowedShopsReturns extends PaginatedDataHookReturnsBase {
|
|
14
|
+
/**
|
|
15
|
+
* The followed shops returned from the query.
|
|
16
|
+
*/
|
|
17
|
+
shops: Shop[] | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const useFollowedShops = (
|
|
21
|
+
params?: UseFollowedShopsParams
|
|
22
|
+
): UseFollowedShopsReturns => {
|
|
23
|
+
const {getFollowedShops} = useShopActions()
|
|
24
|
+
const {skip = false, ...restParams} = params ?? {}
|
|
25
|
+
|
|
26
|
+
const {data, ...rest} = useShopActionsPaginatedDataFetching(
|
|
27
|
+
getFollowedShops,
|
|
28
|
+
restParams,
|
|
29
|
+
{
|
|
30
|
+
skip,
|
|
31
|
+
hook: 'useFollowedShops',
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const shops = useMemo(() => {
|
|
36
|
+
return data ?? null
|
|
37
|
+
}, [data])
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...rest,
|
|
41
|
+
shops,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'
|
|
2
|
+
|
|
3
|
+
const data: ReferenceEntityTemplateSchema = {
|
|
4
|
+
name: 'useRecentProducts',
|
|
5
|
+
category: 'hooks',
|
|
6
|
+
subCategory: 'user',
|
|
7
|
+
isVisualComponent: false,
|
|
8
|
+
related: [],
|
|
9
|
+
description:
|
|
10
|
+
"The `useRecentProducts` hook fetches the current user's recently viewed products.",
|
|
11
|
+
type: 'hook',
|
|
12
|
+
defaultExample: {
|
|
13
|
+
codeblock: {
|
|
14
|
+
tabs: [
|
|
15
|
+
{
|
|
16
|
+
code: './useRecentProducts.example.tsx',
|
|
17
|
+
language: 'tsx',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
title: 'Example code',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
definitions: [
|
|
24
|
+
{
|
|
25
|
+
title: '',
|
|
26
|
+
type: 'UseRecentProductsGeneratedType',
|
|
27
|
+
description: '',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default data
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {useEffect} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useRecentProducts, Button} from '@shopify/shop-minis-react'
|
|
4
|
+
|
|
5
|
+
export default function MyComponent() {
|
|
6
|
+
const {products, fetchMore} = useRecentProducts({first: 10})
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
console.log(products)
|
|
10
|
+
}, [products])
|
|
11
|
+
|
|
12
|
+
return <Button onClick={fetchMore}>Fetch more</Button>
|
|
13
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
4
|
+
import {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'
|
|
5
|
+
import {
|
|
6
|
+
PaginatedDataHookOptionsBase,
|
|
7
|
+
PaginatedDataHookReturnsBase,
|
|
8
|
+
Product,
|
|
9
|
+
} from '../../types'
|
|
10
|
+
|
|
11
|
+
export interface UseRecentProductsParams extends PaginatedDataHookOptionsBase {
|
|
12
|
+
includeSensitive?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface UseRecentProductsReturns extends PaginatedDataHookReturnsBase {
|
|
16
|
+
products: Product[] | null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hook to fetch recently viewed products.
|
|
21
|
+
* @param params - Options for the hook.
|
|
22
|
+
*/
|
|
23
|
+
export const useRecentProducts = (
|
|
24
|
+
params?: UseRecentProductsParams
|
|
25
|
+
): UseRecentProductsReturns => {
|
|
26
|
+
const {getRecentProducts} = useShopActions()
|
|
27
|
+
const {skip, ...shopActionParams} = params ?? {}
|
|
28
|
+
|
|
29
|
+
const {data, ...rest} = useShopActionsPaginatedDataFetching(
|
|
30
|
+
getRecentProducts,
|
|
31
|
+
shopActionParams,
|
|
32
|
+
{
|
|
33
|
+
skip,
|
|
34
|
+
hook: 'useRecentProducts',
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const products = useMemo(() => {
|
|
39
|
+
return data ?? null
|
|
40
|
+
}, [data])
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
...rest,
|
|
44
|
+
products,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useShopActions} from '../../internal/useShopActions'
|
|
4
|
+
import {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'
|
|
5
|
+
import {
|
|
6
|
+
PaginatedDataHookOptionsBase,
|
|
7
|
+
PaginatedDataHookReturnsBase,
|
|
8
|
+
Shop,
|
|
9
|
+
} from '../../types'
|
|
10
|
+
|
|
11
|
+
export interface UseRecentShopsParams extends PaginatedDataHookOptionsBase {}
|
|
12
|
+
|
|
13
|
+
interface UseRecentShopsReturns extends PaginatedDataHookReturnsBase {
|
|
14
|
+
/**
|
|
15
|
+
* The recent shops returned from the query.
|
|
16
|
+
*/
|
|
17
|
+
shops: Shop[] | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const useRecentShops = (
|
|
21
|
+
params?: UseRecentShopsParams
|
|
22
|
+
): UseRecentShopsReturns => {
|
|
23
|
+
const {getRecentShops} = useShopActions()
|
|
24
|
+
const {skip = false, ...restParams} = params ?? {}
|
|
25
|
+
|
|
26
|
+
const {data, ...rest} = useShopActionsPaginatedDataFetching(
|
|
27
|
+
getRecentShops,
|
|
28
|
+
restParams,
|
|
29
|
+
{
|
|
30
|
+
skip,
|
|
31
|
+
hook: 'useRecentShops',
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const shops = useMemo(() => {
|
|
36
|
+
return data ?? null
|
|
37
|
+
}, [data])
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...rest,
|
|
41
|
+
shops,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'
|
|
2
|
+
|
|
3
|
+
const data: ReferenceEntityTemplateSchema = {
|
|
4
|
+
name: 'useSavedProducts',
|
|
5
|
+
category: 'hooks',
|
|
6
|
+
subCategory: 'user',
|
|
7
|
+
isVisualComponent: false,
|
|
8
|
+
related: [],
|
|
9
|
+
description:
|
|
10
|
+
"The `useSavedProducts` hook fetches the current user's saved products.",
|
|
11
|
+
type: 'hook',
|
|
12
|
+
defaultExample: {
|
|
13
|
+
codeblock: {
|
|
14
|
+
tabs: [
|
|
15
|
+
{
|
|
16
|
+
code: './useSavedProducts.example.tsx',
|
|
17
|
+
language: 'tsx',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
title: 'Example code',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
definitions: [
|
|
24
|
+
{
|
|
25
|
+
title: '',
|
|
26
|
+
type: 'UseSavedProductsGeneratedType',
|
|
27
|
+
description: '',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default data
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {useEffect} from 'react'
|
|
2
|
+
|
|
3
|
+
import {useSavedProducts, Button} from '@shopify/shop-minis-react'
|
|
4
|
+
|
|
5
|
+
export default function MyComponent() {
|
|
6
|
+
const {products, fetchMore} = useSavedProducts({first: 10})
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
console.log(products)
|
|
10
|
+
}, [products])
|
|
11
|
+
|
|
12
|
+
return <Button onClick={fetchMore}>Fetch more</Button>
|
|
13
|
+
}
|