@rubixstudios/payload-media 1.2.4 → 1.2.5
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/README.md +1 -1
- package/dist/components/media-search/index.d.ts.map +1 -1
- package/dist/components/media-search/index.js +4 -3
- package/dist/components/search-drawer/filters/pexels.d.ts +4 -4
- package/dist/components/search-drawer/filters/pexels.d.ts.map +1 -1
- package/dist/components/search-drawer/filters/pexels.js +9 -8
- package/dist/components/search-drawer/filters/pixabay.d.ts +4 -4
- package/dist/components/search-drawer/filters/pixabay.d.ts.map +1 -1
- package/dist/components/search-drawer/filters/pixabay.js +11 -11
- package/dist/components/search-drawer/filters/unsplash.d.ts +4 -4
- package/dist/components/search-drawer/filters/unsplash.d.ts.map +1 -1
- package/dist/components/search-drawer/filters/unsplash.js +5 -5
- package/dist/components/search-drawer/index.d.ts +2 -2
- package/dist/components/search-drawer/index.d.ts.map +1 -1
- package/dist/components/search-drawer/index.js +53 -47
- package/dist/components/search-drawer/media/image.d.ts +2 -2
- package/dist/components/search-drawer/media/image.d.ts.map +1 -1
- package/dist/components/search-drawer/media/image.js +2 -2
- package/dist/components/search-drawer/media/video.d.ts +2 -2
- package/dist/components/search-drawer/media/video.d.ts.map +1 -1
- package/dist/components/search-drawer/media/video.js +5 -3
- package/dist/endpoints/handler/Pexels.d.ts.map +1 -1
- package/dist/endpoints/handler/Pexels.js +7 -21
- package/dist/endpoints/handler/Pixabay.d.ts.map +1 -1
- package/dist/endpoints/handler/Pixabay.js +9 -22
- package/dist/endpoints/handler/Provider.d.ts +3 -3
- package/dist/endpoints/handler/Provider.d.ts.map +1 -1
- package/dist/endpoints/handler/Provider.js +11 -11
- package/dist/endpoints/handler/Unsplash.d.ts.map +1 -1
- package/dist/endpoints/handler/Unsplash.js +2 -6
- package/dist/endpoints/index.d.ts.map +1 -1
- package/dist/endpoints/index.js +42 -75
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -19
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/lib/cache.js +12 -9
- package/dist/types.d.ts +101 -100
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/fetchCache.d.ts.map +1 -1
- package/dist/utils/fetchCache.js +4 -4
- package/dist/utils/getProviders.d.ts +1 -1
- package/dist/utils/getProviders.d.ts.map +1 -1
- package/dist/utils/getProviders.js +6 -6
- package/dist/utils/resolveProvider.d.ts +1 -4
- package/dist/utils/resolveProvider.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-search/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAK1C,eAAO,MAAM,UAAU,yBAAyB,CAAA;AAEhD,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-search/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAK1C,eAAO,MAAM,UAAU,yBAAyB,CAAA;AAEhD,eAAO,MAAM,WAAW,yBAgCvB,CAAA"}
|
|
@@ -7,7 +7,7 @@ export const MediaSearch = ()=>{
|
|
|
7
7
|
const { config } = useConfig();
|
|
8
8
|
const { setUploadControlFileUrl } = useUploadControls();
|
|
9
9
|
const { openModal, closeModal } = useModal();
|
|
10
|
-
const
|
|
10
|
+
const handleSubmit = useCallback((url)=>{
|
|
11
11
|
if (!url) return;
|
|
12
12
|
setUploadControlFileUrl(url);
|
|
13
13
|
closeModal(drawerSlug);
|
|
@@ -22,10 +22,11 @@ export const MediaSearch = ()=>{
|
|
|
22
22
|
onClick: ()=>openModal(drawerSlug),
|
|
23
23
|
size: "small"
|
|
24
24
|
}, "Search media"), /*#__PURE__*/ React.createElement(Drawer, {
|
|
25
|
-
slug: drawerSlug
|
|
25
|
+
slug: drawerSlug,
|
|
26
|
+
title: "Media"
|
|
26
27
|
}, /*#__PURE__*/ React.createElement(SearchDrawer, {
|
|
27
28
|
api: config.routes.api,
|
|
28
|
-
onSelect:
|
|
29
|
+
onSelect: handleSubmit,
|
|
29
30
|
serverURL: config.serverURL
|
|
30
31
|
})));
|
|
31
32
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { type Dispatch, type SetStateAction } from 'react';
|
|
2
2
|
import { type ProviderFilters } from '../../../types.js';
|
|
3
|
-
type
|
|
3
|
+
type Props = {
|
|
4
4
|
filters: ProviderFilters;
|
|
5
5
|
mediaType: 'image' | 'video';
|
|
6
|
-
setFilters:
|
|
6
|
+
setFilters: Dispatch<SetStateAction<ProviderFilters | null>>;
|
|
7
7
|
baseClass: string;
|
|
8
8
|
};
|
|
9
|
-
export declare const PexelsFilters: ({ filters, mediaType, setFilters, baseClass
|
|
9
|
+
export declare const PexelsFilters: ({ filters, mediaType, setFilters, baseClass }: Props) => React.JSX.Element | null;
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=pexels.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pexels.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/filters/pexels.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"pexels.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/filters/pexels.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAA;AAGjE,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,mBAAmB,CAAA;AAE1B,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,eAAe,CAAA;IACxB,SAAS,EAAE,OAAO,GAAG,OAAO,CAAA;IAC5B,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAA;IAC5D,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,aAAa,kDAAmD,KAAK,6BAyEjF,CAAA"}
|
|
@@ -2,14 +2,15 @@ import React from 'react';
|
|
|
2
2
|
import { Select } from '@payloadcms/ui';
|
|
3
3
|
import { PexelsColours, PexelsOrientation, PexelsSize, PexelsVideoSize } from '../../../types.js';
|
|
4
4
|
export const PexelsFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
5
|
-
if (filters
|
|
5
|
+
if (filters.provider !== 'pexels') return null;
|
|
6
|
+
const sizeOptions = mediaType === 'video' ? PexelsVideoSize : PexelsSize;
|
|
6
7
|
return /*#__PURE__*/ React.createElement("div", {
|
|
7
8
|
className: `${baseClass}__filters`
|
|
8
9
|
}, mediaType !== 'video' && /*#__PURE__*/ React.createElement(Select, {
|
|
9
10
|
isClearable: true,
|
|
10
11
|
isSearchable: false,
|
|
11
12
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'pexels' ? {
|
|
12
|
-
|
|
13
|
+
...prev,
|
|
13
14
|
options: {
|
|
14
15
|
...prev.options,
|
|
15
16
|
color: opt?.value
|
|
@@ -17,25 +18,25 @@ export const PexelsFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
|
17
18
|
} : prev),
|
|
18
19
|
options: PexelsColours,
|
|
19
20
|
placeholder: "Colour",
|
|
20
|
-
value: PexelsColours.find((
|
|
21
|
+
value: PexelsColours.find((option)=>option.value === filters.options.color)
|
|
21
22
|
}), /*#__PURE__*/ React.createElement(Select, {
|
|
22
23
|
isClearable: true,
|
|
23
24
|
isSearchable: false,
|
|
24
25
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'pexels' ? {
|
|
25
|
-
|
|
26
|
+
...prev,
|
|
26
27
|
options: {
|
|
27
28
|
...prev.options,
|
|
28
29
|
size: opt?.value
|
|
29
30
|
}
|
|
30
31
|
} : prev),
|
|
31
|
-
options:
|
|
32
|
+
options: sizeOptions,
|
|
32
33
|
placeholder: "Size",
|
|
33
|
-
value:
|
|
34
|
+
value: sizeOptions.find((option)=>option.value === filters.options.size)
|
|
34
35
|
}), /*#__PURE__*/ React.createElement(Select, {
|
|
35
36
|
isClearable: true,
|
|
36
37
|
isSearchable: false,
|
|
37
38
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'pexels' ? {
|
|
38
|
-
|
|
39
|
+
...prev,
|
|
39
40
|
options: {
|
|
40
41
|
...prev.options,
|
|
41
42
|
orientation: opt?.value
|
|
@@ -43,6 +44,6 @@ export const PexelsFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
|
43
44
|
} : prev),
|
|
44
45
|
options: PexelsOrientation,
|
|
45
46
|
placeholder: "Orientation",
|
|
46
|
-
value: PexelsOrientation.find((
|
|
47
|
+
value: PexelsOrientation.find((option)=>option.value === filters.options.orientation)
|
|
47
48
|
}));
|
|
48
49
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { type Dispatch, type SetStateAction } from 'react';
|
|
2
2
|
import { type ProviderFilters } from '../../../types.js';
|
|
3
|
-
type
|
|
3
|
+
type Props = {
|
|
4
4
|
filters: ProviderFilters;
|
|
5
5
|
mediaType: 'image' | 'video';
|
|
6
|
-
setFilters:
|
|
6
|
+
setFilters: Dispatch<SetStateAction<ProviderFilters | null>>;
|
|
7
7
|
baseClass: string;
|
|
8
8
|
};
|
|
9
|
-
export declare const PixabayFilters: ({ filters, mediaType, setFilters, baseClass
|
|
9
|
+
export declare const PixabayFilters: ({ filters, mediaType, setFilters, baseClass }: Props) => React.JSX.Element | null;
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=pixabay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixabay.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/filters/pixabay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"pixabay.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/filters/pixabay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAA;AAGjE,OAAO,EAML,KAAK,eAAe,EAErB,MAAM,mBAAmB,CAAA;AAE1B,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,eAAe,CAAA;IACxB,SAAS,EAAE,OAAO,GAAG,OAAO,CAAA;IAC5B,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAA;IAC5D,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,cAAc,kDAAmD,KAAK,6BAqHlF,CAAA"}
|
|
@@ -2,14 +2,14 @@ import React from 'react';
|
|
|
2
2
|
import { Select } from '@payloadcms/ui';
|
|
3
3
|
import { PixabayCategories, PixabayColours, PixabayImageType, PixabayOrder, PixabayOrientation } from '../../../types.js';
|
|
4
4
|
export const PixabayFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
5
|
-
if (filters
|
|
5
|
+
if (filters.provider !== 'pixabay') return null;
|
|
6
6
|
return /*#__PURE__*/ React.createElement("div", {
|
|
7
7
|
className: `${baseClass}__filters`
|
|
8
8
|
}, /*#__PURE__*/ React.createElement(Select, {
|
|
9
9
|
isClearable: true,
|
|
10
10
|
isSearchable: false,
|
|
11
11
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'pixabay' ? {
|
|
12
|
-
|
|
12
|
+
...prev,
|
|
13
13
|
options: {
|
|
14
14
|
...prev.options,
|
|
15
15
|
category: opt?.value
|
|
@@ -17,12 +17,12 @@ export const PixabayFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
|
17
17
|
} : prev),
|
|
18
18
|
options: PixabayCategories,
|
|
19
19
|
placeholder: "Category",
|
|
20
|
-
value: PixabayCategories.find((
|
|
20
|
+
value: PixabayCategories.find((option)=>option.value === filters.options.category)
|
|
21
21
|
}), mediaType !== 'video' && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Select, {
|
|
22
22
|
isClearable: true,
|
|
23
23
|
isSearchable: false,
|
|
24
24
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'pixabay' ? {
|
|
25
|
-
|
|
25
|
+
...prev,
|
|
26
26
|
options: {
|
|
27
27
|
...prev.options,
|
|
28
28
|
image_type: opt?.value
|
|
@@ -30,12 +30,12 @@ export const PixabayFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
|
30
30
|
} : prev),
|
|
31
31
|
options: PixabayImageType,
|
|
32
32
|
placeholder: "Type",
|
|
33
|
-
value: PixabayImageType.find((
|
|
33
|
+
value: PixabayImageType.find((option)=>option.value === filters.options.image_type)
|
|
34
34
|
}), /*#__PURE__*/ React.createElement(Select, {
|
|
35
35
|
isClearable: true,
|
|
36
36
|
isSearchable: false,
|
|
37
37
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'pixabay' ? {
|
|
38
|
-
|
|
38
|
+
...prev,
|
|
39
39
|
options: {
|
|
40
40
|
...prev.options,
|
|
41
41
|
colors: opt?.value
|
|
@@ -43,12 +43,12 @@ export const PixabayFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
|
43
43
|
} : prev),
|
|
44
44
|
options: PixabayColours,
|
|
45
45
|
placeholder: "Colour",
|
|
46
|
-
value: PixabayColours.find((
|
|
46
|
+
value: PixabayColours.find((option)=>option.value === filters.options.colors)
|
|
47
47
|
}), /*#__PURE__*/ React.createElement(Select, {
|
|
48
48
|
isClearable: true,
|
|
49
49
|
isSearchable: false,
|
|
50
50
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'pixabay' ? {
|
|
51
|
-
|
|
51
|
+
...prev,
|
|
52
52
|
options: {
|
|
53
53
|
...prev.options,
|
|
54
54
|
orientation: opt?.value
|
|
@@ -56,12 +56,12 @@ export const PixabayFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
|
56
56
|
} : prev),
|
|
57
57
|
options: PixabayOrientation,
|
|
58
58
|
placeholder: "Orientation",
|
|
59
|
-
value: PixabayOrientation.find((
|
|
59
|
+
value: PixabayOrientation.find((option)=>option.value === filters.options.orientation)
|
|
60
60
|
})), /*#__PURE__*/ React.createElement(Select, {
|
|
61
61
|
isClearable: true,
|
|
62
62
|
isSearchable: false,
|
|
63
63
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'pixabay' ? {
|
|
64
|
-
|
|
64
|
+
...prev,
|
|
65
65
|
options: {
|
|
66
66
|
...prev.options,
|
|
67
67
|
order: opt?.value
|
|
@@ -69,6 +69,6 @@ export const PixabayFilters = ({ filters, mediaType, setFilters, baseClass })=>{
|
|
|
69
69
|
} : prev),
|
|
70
70
|
options: PixabayOrder,
|
|
71
71
|
placeholder: "Order",
|
|
72
|
-
value: PixabayOrder.find((
|
|
72
|
+
value: PixabayOrder.find((option)=>option.value === filters.options.order)
|
|
73
73
|
}));
|
|
74
74
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { type Dispatch, type SetStateAction } from 'react';
|
|
2
2
|
import { type ProviderFilters } from '../../../types.js';
|
|
3
|
-
type
|
|
3
|
+
type Props = {
|
|
4
4
|
filters: ProviderFilters;
|
|
5
|
-
setFilters:
|
|
5
|
+
setFilters: Dispatch<SetStateAction<ProviderFilters | null>>;
|
|
6
6
|
baseClass: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const UnsplashFilters: ({ filters, setFilters, baseClass }:
|
|
8
|
+
export declare const UnsplashFilters: ({ filters, setFilters, baseClass }: Props) => React.JSX.Element | null;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=unsplash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsplash.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/filters/unsplash.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"unsplash.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/filters/unsplash.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAA;AAGjE,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,mBAAmB,CAAA;AAE1B,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAA;IAC5D,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,eAAe,uCAAwC,KAAK,6BAgDxE,CAAA"}
|
|
@@ -2,14 +2,14 @@ import React from 'react';
|
|
|
2
2
|
import { Select } from '@payloadcms/ui';
|
|
3
3
|
import { UnsplashColours, UnsplashOrientation } from '../../../types.js';
|
|
4
4
|
export const UnsplashFilters = ({ filters, setFilters, baseClass })=>{
|
|
5
|
-
if (filters
|
|
5
|
+
if (filters.provider !== 'unsplash') return null;
|
|
6
6
|
return /*#__PURE__*/ React.createElement("div", {
|
|
7
7
|
className: `${baseClass}__filters`
|
|
8
8
|
}, /*#__PURE__*/ React.createElement(Select, {
|
|
9
9
|
isClearable: true,
|
|
10
10
|
isSearchable: false,
|
|
11
11
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'unsplash' ? {
|
|
12
|
-
|
|
12
|
+
...prev,
|
|
13
13
|
options: {
|
|
14
14
|
...prev.options,
|
|
15
15
|
color: opt?.value
|
|
@@ -17,12 +17,12 @@ export const UnsplashFilters = ({ filters, setFilters, baseClass })=>{
|
|
|
17
17
|
} : prev),
|
|
18
18
|
options: UnsplashColours,
|
|
19
19
|
placeholder: "Colour",
|
|
20
|
-
value: UnsplashColours.find((
|
|
20
|
+
value: UnsplashColours.find((option)=>option.value === filters.options.color)
|
|
21
21
|
}), /*#__PURE__*/ React.createElement(Select, {
|
|
22
22
|
isClearable: true,
|
|
23
23
|
isSearchable: false,
|
|
24
24
|
onChange: (opt)=>setFilters((prev)=>prev?.provider === 'unsplash' ? {
|
|
25
|
-
|
|
25
|
+
...prev,
|
|
26
26
|
options: {
|
|
27
27
|
...prev.options,
|
|
28
28
|
orientation: opt?.value
|
|
@@ -30,6 +30,6 @@ export const UnsplashFilters = ({ filters, setFilters, baseClass })=>{
|
|
|
30
30
|
} : prev),
|
|
31
31
|
options: UnsplashOrientation,
|
|
32
32
|
placeholder: "Orientation",
|
|
33
|
-
value: UnsplashOrientation.find((
|
|
33
|
+
value: UnsplashOrientation.find((option)=>option.value === filters.options.orientation)
|
|
34
34
|
}));
|
|
35
35
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import './style.css';
|
|
3
|
-
export type
|
|
3
|
+
export type Props = {
|
|
4
4
|
serverURL: string;
|
|
5
5
|
api: string;
|
|
6
6
|
onSelect: (value: string) => void;
|
|
7
7
|
};
|
|
8
|
-
export declare const SearchDrawer: (props:
|
|
8
|
+
export declare const SearchDrawer: (props: Props) => React.JSX.Element;
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/search-drawer/index.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/search-drawer/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAqD,MAAM,OAAO,CAAA;AAgBzE,OAAO,aAAa,CAAA;AAIpB,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,YAAY,UAAW,KAAK,sBA6UxC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import React, { Fragment, useCallback, useEffect, useState } from 'react';
|
|
3
3
|
import { Pagination, SearchFilter, Select, toast } from '@payloadcms/ui';
|
|
4
4
|
import { MediaOptions } from '../../types.js';
|
|
5
5
|
import { fetchCache } from '../../utils/fetchCache.js';
|
|
@@ -12,16 +12,17 @@ import './style.css';
|
|
|
12
12
|
const baseClass = 'search-media';
|
|
13
13
|
export const SearchDrawer = (props)=>{
|
|
14
14
|
const { serverURL, api, onSelect } = props;
|
|
15
|
-
const [
|
|
15
|
+
const [provider, setProvider] = useState(null);
|
|
16
16
|
const [options, setOptions] = useState([]);
|
|
17
|
-
const [mediaType, setMediaType] = useState('image');
|
|
18
17
|
const [media, setMedia] = useState(null);
|
|
18
|
+
const [mediaType, setMediaType] = useState('image');
|
|
19
19
|
const [filters, setFilters] = useState(null);
|
|
20
20
|
const [currentPage, setCurrentPage] = useState(null);
|
|
21
21
|
const [totalPages, setTotalPages] = useState(null);
|
|
22
22
|
const [loading, setLoading] = useState(true);
|
|
23
23
|
const [value, setValue] = useState('');
|
|
24
|
-
const
|
|
24
|
+
const mediaOptions = MediaOptions.filter((option)=>filters?.provider === 'unsplash' ? option.value === 'image' : true);
|
|
25
|
+
const error = useCallback(()=>{
|
|
25
26
|
toast.error('Something went wrong.');
|
|
26
27
|
}, []);
|
|
27
28
|
const resetMedia = useCallback(()=>{
|
|
@@ -51,17 +52,17 @@ export const SearchDrawer = (props)=>{
|
|
|
51
52
|
provider: initial.value,
|
|
52
53
|
options: {}
|
|
53
54
|
});
|
|
54
|
-
|
|
55
|
+
setProvider(initial);
|
|
55
56
|
} catch {
|
|
56
57
|
setLoading(false);
|
|
57
|
-
|
|
58
|
+
error();
|
|
58
59
|
}
|
|
59
60
|
}, [
|
|
60
61
|
serverURL,
|
|
61
62
|
api,
|
|
62
|
-
|
|
63
|
+
error
|
|
63
64
|
]);
|
|
64
|
-
const
|
|
65
|
+
const buildFeatures = useCallback(()=>{
|
|
65
66
|
if (!filters || !mediaType) return '';
|
|
66
67
|
const params = new URLSearchParams();
|
|
67
68
|
switch(filters.provider){
|
|
@@ -99,11 +100,11 @@ export const SearchDrawer = (props)=>{
|
|
|
99
100
|
filters,
|
|
100
101
|
mediaType
|
|
101
102
|
]);
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
103
|
+
const getFeatures = useCallback(async ()=>{
|
|
104
|
+
if (!provider || !filters || !mediaType) return;
|
|
104
105
|
try {
|
|
105
106
|
setLoading(true);
|
|
106
|
-
const json = await fetchCache(`${serverURL}${api}/providers/${
|
|
107
|
+
const json = await fetchCache(`${serverURL}${api}/providers/${provider.value}/featured${buildFeatures()}`);
|
|
107
108
|
if (!json) return;
|
|
108
109
|
if (json.error) {
|
|
109
110
|
toast.error(json.error);
|
|
@@ -111,18 +112,18 @@ export const SearchDrawer = (props)=>{
|
|
|
111
112
|
}
|
|
112
113
|
setMedia(json.data.images);
|
|
113
114
|
} catch {
|
|
114
|
-
|
|
115
|
+
error();
|
|
115
116
|
} finally{
|
|
116
117
|
setLoading(false);
|
|
117
118
|
}
|
|
118
119
|
}, [
|
|
119
120
|
serverURL,
|
|
120
121
|
api,
|
|
121
|
-
|
|
122
|
+
provider,
|
|
122
123
|
filters,
|
|
123
|
-
|
|
124
|
+
buildFeatures,
|
|
124
125
|
mediaType,
|
|
125
|
-
|
|
126
|
+
error
|
|
126
127
|
]);
|
|
127
128
|
const buildQuery = useCallback((page = 1)=>{
|
|
128
129
|
if (!filters || !mediaType) return '';
|
|
@@ -167,38 +168,39 @@ export const SearchDrawer = (props)=>{
|
|
|
167
168
|
const getMedia = useCallback(async (page = 1)=>{
|
|
168
169
|
try {
|
|
169
170
|
setLoading(true);
|
|
170
|
-
const json = await fetchCache(`${serverURL}${api}/providers/${
|
|
171
|
+
const json = await fetchCache(`${serverURL}${api}/providers/${provider?.value}/search?${buildQuery(page)}`);
|
|
171
172
|
if (json.error) return toast.error(json.error);
|
|
172
173
|
setMedia(json.data.images);
|
|
173
174
|
setTotalPages(json.data.totalPages);
|
|
174
175
|
setCurrentPage(page);
|
|
175
176
|
} catch {
|
|
176
|
-
|
|
177
|
+
error();
|
|
177
178
|
} finally{
|
|
178
179
|
setLoading(false);
|
|
179
180
|
}
|
|
180
181
|
}, [
|
|
181
182
|
serverURL,
|
|
182
183
|
api,
|
|
183
|
-
|
|
184
|
-
|
|
184
|
+
provider?.value,
|
|
185
|
+
error,
|
|
185
186
|
buildQuery
|
|
186
187
|
]);
|
|
187
188
|
const selectMedia = async (url, download)=>{
|
|
188
189
|
onSelect(url);
|
|
189
190
|
if (!download) return;
|
|
190
191
|
try {
|
|
191
|
-
await fetch(`${serverURL}${api}/providers/${
|
|
192
|
+
await fetch(`${serverURL}${api}/providers/${provider?.value}/track-download?url=${encodeURIComponent(download)}`);
|
|
192
193
|
} catch {
|
|
193
194
|
return null;
|
|
194
195
|
}
|
|
195
196
|
};
|
|
196
|
-
const selectFilter = useCallback((
|
|
197
|
+
const selectFilter = useCallback((value)=>{
|
|
198
|
+
const select = value;
|
|
197
199
|
setFilters({
|
|
198
200
|
provider: select.value,
|
|
199
201
|
options: {}
|
|
200
202
|
});
|
|
201
|
-
|
|
203
|
+
setProvider(select);
|
|
202
204
|
if (select.value === 'unsplash') {
|
|
203
205
|
setMediaType('image');
|
|
204
206
|
}
|
|
@@ -206,31 +208,49 @@ export const SearchDrawer = (props)=>{
|
|
|
206
208
|
}, [
|
|
207
209
|
resetMedia
|
|
208
210
|
]);
|
|
211
|
+
const selectType = useCallback((option)=>{
|
|
212
|
+
const value = option?.value;
|
|
213
|
+
setMediaType(value);
|
|
214
|
+
resetMedia();
|
|
215
|
+
}, [
|
|
216
|
+
resetMedia
|
|
217
|
+
]);
|
|
209
218
|
const changeFilters = useCallback((search)=>{
|
|
210
219
|
setValue(search);
|
|
211
220
|
resetMedia();
|
|
212
221
|
}, [
|
|
213
222
|
resetMedia
|
|
214
223
|
]);
|
|
224
|
+
const renderMedia = (data)=>/*#__PURE__*/ React.createElement(Fragment, {
|
|
225
|
+
key: data.id
|
|
226
|
+
}, mediaType === 'video' ? /*#__PURE__*/ React.createElement(VideoCard, {
|
|
227
|
+
baseClass: baseClass,
|
|
228
|
+
data: data,
|
|
229
|
+
onSelect: selectMedia
|
|
230
|
+
}) : /*#__PURE__*/ React.createElement(ImageCard, {
|
|
231
|
+
baseClass: baseClass,
|
|
232
|
+
data: data,
|
|
233
|
+
onSelect: selectMedia
|
|
234
|
+
}));
|
|
215
235
|
useEffect(()=>{
|
|
216
236
|
void getOptions();
|
|
217
237
|
}, [
|
|
218
238
|
getOptions
|
|
219
239
|
]);
|
|
220
240
|
useEffect(()=>{
|
|
221
|
-
if (!
|
|
241
|
+
if (!provider?.value || !filters || !mediaType) return;
|
|
222
242
|
if (value.trim().length > 0) {
|
|
223
243
|
void getMedia(1);
|
|
224
244
|
} else {
|
|
225
|
-
void
|
|
245
|
+
void getFeatures();
|
|
226
246
|
}
|
|
227
247
|
}, [
|
|
228
|
-
|
|
248
|
+
provider?.value,
|
|
229
249
|
filters,
|
|
230
250
|
value,
|
|
231
251
|
mediaType,
|
|
232
252
|
getMedia,
|
|
233
|
-
|
|
253
|
+
getFeatures
|
|
234
254
|
]);
|
|
235
255
|
return /*#__PURE__*/ React.createElement("div", {
|
|
236
256
|
className: baseClass
|
|
@@ -238,18 +258,14 @@ export const SearchDrawer = (props)=>{
|
|
|
238
258
|
className: `${baseClass}__fields`
|
|
239
259
|
}, /*#__PURE__*/ React.createElement(SearchFilter, {
|
|
240
260
|
handleChange: changeFilters,
|
|
241
|
-
label: ""
|
|
261
|
+
label: "Search..."
|
|
242
262
|
}), /*#__PURE__*/ React.createElement(Select, {
|
|
243
263
|
className: `${baseClass}__mediaToggle`,
|
|
244
264
|
isClearable: false,
|
|
245
265
|
isCreatable: false,
|
|
246
266
|
isSearchable: false,
|
|
247
|
-
onChange:
|
|
248
|
-
|
|
249
|
-
setMediaType(val);
|
|
250
|
-
resetMedia();
|
|
251
|
-
},
|
|
252
|
-
options: MediaOptions.filter((option)=>filters?.provider === 'unsplash' ? option.value === 'image' : true),
|
|
267
|
+
onChange: selectType,
|
|
268
|
+
options: mediaOptions,
|
|
253
269
|
value: {
|
|
254
270
|
label: mediaType === 'image' ? 'Images' : 'Videos',
|
|
255
271
|
value: mediaType
|
|
@@ -259,9 +275,9 @@ export const SearchDrawer = (props)=>{
|
|
|
259
275
|
isClearable: false,
|
|
260
276
|
isCreatable: false,
|
|
261
277
|
isSearchable: false,
|
|
262
|
-
onChange:
|
|
278
|
+
onChange: selectFilter,
|
|
263
279
|
options: options,
|
|
264
|
-
value:
|
|
280
|
+
value: provider
|
|
265
281
|
})), filters?.provider === 'pexels' && /*#__PURE__*/ React.createElement(PexelsFilters, {
|
|
266
282
|
baseClass: baseClass,
|
|
267
283
|
filters: filters,
|
|
@@ -282,24 +298,14 @@ export const SearchDrawer = (props)=>{
|
|
|
282
298
|
className: `${baseClass}__noResults`
|
|
283
299
|
}, "No media found"), !loading && media && media?.length > 0 && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("div", {
|
|
284
300
|
className: `${baseClass}__results`
|
|
285
|
-
}, media.map(
|
|
286
|
-
key: data.id
|
|
287
|
-
}, mediaType === 'video' ? /*#__PURE__*/ React.createElement(VideoCard, {
|
|
288
|
-
baseClass: baseClass,
|
|
289
|
-
data: data,
|
|
290
|
-
onSelect: selectMedia
|
|
291
|
-
}) : /*#__PURE__*/ React.createElement(ImageCard, {
|
|
292
|
-
baseClass: baseClass,
|
|
293
|
-
data: data,
|
|
294
|
-
onSelect: selectMedia
|
|
295
|
-
})))), currentPage && totalPages && totalPages > 1 && /*#__PURE__*/ React.createElement("div", {
|
|
301
|
+
}, media.map(renderMedia)), currentPage && totalPages && totalPages > 1 && /*#__PURE__*/ React.createElement("div", {
|
|
296
302
|
className: `${baseClass}__pagination`
|
|
297
303
|
}, /*#__PURE__*/ React.createElement(Pagination, {
|
|
298
304
|
hasNextPage: currentPage < totalPages,
|
|
299
305
|
hasPrevPage: currentPage > 1,
|
|
300
306
|
nextPage: currentPage < totalPages ? currentPage + 1 : undefined,
|
|
301
307
|
numberOfNeighbors: 3,
|
|
302
|
-
onChange:
|
|
308
|
+
onChange: getMedia,
|
|
303
309
|
page: currentPage,
|
|
304
310
|
prevPage: currentPage > 1 ? currentPage - 1 : undefined,
|
|
305
311
|
totalPages: totalPages
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type ProviderResult } from '../../../types.js';
|
|
3
|
-
type
|
|
3
|
+
type Props = {
|
|
4
4
|
data: ProviderResult;
|
|
5
5
|
baseClass: string;
|
|
6
6
|
onSelect: (url: string, download?: string) => void;
|
|
7
7
|
};
|
|
8
|
-
export declare const ImageCard: ({ data, baseClass, onSelect }:
|
|
8
|
+
export declare const ImageCard: ({ data, baseClass, onSelect }: Props) => React.JSX.Element;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=image.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/media/image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAGvC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGvD,KAAK,
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/media/image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAGvC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGvD,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,cAAc,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CACnD,CAAA;AAED,eAAO,MAAM,SAAS,kCAAmC,KAAK,sBAqE7D,CAAA"}
|
|
@@ -4,8 +4,7 @@ import { HeartIcon } from './heart.js';
|
|
|
4
4
|
export const ImageCard = ({ data, baseClass, onSelect })=>{
|
|
5
5
|
const [show, setShow] = useState(false);
|
|
6
6
|
return /*#__PURE__*/ React.createElement("div", {
|
|
7
|
-
className: `${baseClass}__card
|
|
8
|
-
key: data.id
|
|
7
|
+
className: `${baseClass}__card`
|
|
9
8
|
}, /*#__PURE__*/ React.createElement("button", {
|
|
10
9
|
className: `${baseClass}__button`,
|
|
11
10
|
onClick: ()=>onSelect(data.urls.original, data.urls?.downloadLocation),
|
|
@@ -21,6 +20,7 @@ export const ImageCard = ({ data, baseClass, onSelect })=>{
|
|
|
21
20
|
})), /*#__PURE__*/ React.createElement("div", {
|
|
22
21
|
className: `${baseClass}__topOverlay`
|
|
23
22
|
}, data.likes !== undefined && /*#__PURE__*/ React.createElement("button", {
|
|
23
|
+
"aria-label": `${data.likes} likes`,
|
|
24
24
|
className: `${baseClass}__likes`,
|
|
25
25
|
onBlur: ()=>setShow(false),
|
|
26
26
|
onFocus: ()=>setShow(true),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type ProviderResult } from '../../../types.js';
|
|
3
|
-
type
|
|
3
|
+
type Props = {
|
|
4
4
|
data: ProviderResult;
|
|
5
5
|
baseClass: string;
|
|
6
6
|
onSelect: (url: string, download?: string) => void;
|
|
7
7
|
};
|
|
8
|
-
export declare const VideoCard: ({ data, baseClass, onSelect }:
|
|
8
|
+
export declare const VideoCard: ({ data, baseClass, onSelect }: Props) => React.JSX.Element;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=video.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/media/video.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAGvC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAIvD,KAAK,
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../../src/components/search-drawer/media/video.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAGvC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAIvD,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,cAAc,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CACnD,CAAA;AAED,eAAO,MAAM,SAAS,kCAAmC,KAAK,sBAkF7D,CAAA"}
|
|
@@ -5,8 +5,7 @@ import { PlusIcon } from './plus.js';
|
|
|
5
5
|
export const VideoCard = ({ data, baseClass, onSelect })=>{
|
|
6
6
|
const [show, setShow] = useState(false);
|
|
7
7
|
return /*#__PURE__*/ React.createElement("div", {
|
|
8
|
-
className: `${baseClass}__video
|
|
9
|
-
key: data.id
|
|
8
|
+
className: `${baseClass}__video`
|
|
10
9
|
}, /*#__PURE__*/ React.createElement("video", {
|
|
11
10
|
controls: true,
|
|
12
11
|
poster: data.urls.view,
|
|
@@ -37,6 +36,7 @@ export const VideoCard = ({ data, baseClass, onSelect })=>{
|
|
|
37
36
|
}), data.attribution.name), /*#__PURE__*/ React.createElement("div", {
|
|
38
37
|
className: `${baseClass}__actions`
|
|
39
38
|
}, data.likes !== undefined && /*#__PURE__*/ React.createElement("button", {
|
|
39
|
+
"aria-label": `${data.likes} likes`,
|
|
40
40
|
className: `${baseClass}__likes`,
|
|
41
41
|
onBlur: ()=>setShow(false),
|
|
42
42
|
onFocus: ()=>setShow(true),
|
|
@@ -48,10 +48,12 @@ export const VideoCard = ({ data, baseClass, onSelect })=>{
|
|
|
48
48
|
position: "bottom",
|
|
49
49
|
show: show
|
|
50
50
|
}, data.likes, " likes")), /*#__PURE__*/ React.createElement("button", {
|
|
51
|
+
"aria-label": "Select video",
|
|
51
52
|
className: `${baseClass}__add`,
|
|
52
|
-
onClick: ()=>onSelect
|
|
53
|
+
onClick: ()=>onSelect(data.urls.original, data.urls.download),
|
|
53
54
|
type: "button"
|
|
54
55
|
}, /*#__PURE__*/ React.createElement(PlusIcon, null)), /*#__PURE__*/ React.createElement("a", {
|
|
56
|
+
"aria-label": "Open video download",
|
|
55
57
|
className: `${baseClass}__download`,
|
|
56
58
|
href: data.urls.download,
|
|
57
59
|
rel: "noopener noreferrer",
|