@ludo.ninja/components 1.4.0 → 1.4.1
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/package.json
CHANGED
|
@@ -11,7 +11,7 @@ import CollectionCreationEntity from '@/dto/Collection/CollectionCreationEntity'
|
|
|
11
11
|
import CreationEntity from '@/dto/CreationEntity';
|
|
12
12
|
import GalleryEntityV2 from '@/dto/GalleryEntityV2';
|
|
13
13
|
|
|
14
|
-
import { getMediaForGallery } from
|
|
14
|
+
import { getMediaForGallery } from "@/hooks/favorites";
|
|
15
15
|
|
|
16
16
|
const useGetFavoriteGallaryCreations = ({
|
|
17
17
|
galleryId,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useGetUserGalleriesCreations';
|
|
@@ -3,18 +3,12 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
3
3
|
import { useLazyQuery, useQuery } from '@apollo/client';
|
|
4
4
|
|
|
5
5
|
import { hosts } from '@ludo.ninja/api';
|
|
6
|
-
import { IAsset } from '@ludo.ninja/api/build/graphql_tools/__generated__/assetsHost/schema';
|
|
7
|
-
import { ICollectionAsset } from '@ludo.ninja/api/build/graphql_tools/__generated__/collectionsHost/schema';
|
|
8
6
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
FetchAssetsDocument,
|
|
15
|
-
FetchCollectionsByIdsDocument,
|
|
16
|
-
ICreation,
|
|
17
|
-
} from '@ludo.ninja/api/build/graphql_tools/__generated__/searchHost/schema';
|
|
7
|
+
galleriesSchema,
|
|
8
|
+
searchSchema,
|
|
9
|
+
collectionsSchema,
|
|
10
|
+
assetSchema
|
|
11
|
+
} from '@ludo.ninja/api';
|
|
18
12
|
import { alertVariants } from '@ludo.ninja/ui/build/system/Alert/type';
|
|
19
13
|
|
|
20
14
|
import { useUiStore } from '@/store/ui';
|
|
@@ -22,6 +16,7 @@ import { useUiStore } from '@/store/ui';
|
|
|
22
16
|
import CollectionCreationEntity from '@/dto/Collection/CollectionCreationEntity';
|
|
23
17
|
import CreationEntity from '@/dto/CreationEntity';
|
|
24
18
|
import GalleryEntityV2 from '@/dto/GalleryEntityV2';
|
|
19
|
+
import { getMediaForGallery } from "@/hooks/favorites";
|
|
25
20
|
|
|
26
21
|
const maxUserFavoritesLength = 1000;
|
|
27
22
|
|
|
@@ -29,7 +24,7 @@ const useGetUserGalleriesCreations = ({
|
|
|
29
24
|
userId,
|
|
30
25
|
pageSize,
|
|
31
26
|
pageToken,
|
|
32
|
-
}: IQueryFetchUserGalleriesV2Args) => {
|
|
27
|
+
}: galleriesSchema.IQueryFetchUserGalleriesV2Args) => {
|
|
33
28
|
const [assets, setAsset] = useState<CreationEntity[] | null>(null);
|
|
34
29
|
const [collections, setCollections] = useState<
|
|
35
30
|
CollectionCreationEntity[] | null
|
|
@@ -48,7 +43,7 @@ const useGetUserGalleriesCreations = ({
|
|
|
48
43
|
error: galleriesError,
|
|
49
44
|
refetch,
|
|
50
45
|
fetchMore,
|
|
51
|
-
} = useQuery(FetchUserGalleriesV2Document, {
|
|
46
|
+
} = useQuery(galleriesSchema.FetchUserGalleriesV2Document, {
|
|
52
47
|
context: { uri: hosts.galleriesHost },
|
|
53
48
|
variables: { pageSize, userId, pageToken },
|
|
54
49
|
fetchPolicy: 'no-cache',
|
|
@@ -58,7 +53,7 @@ const useGetUserGalleriesCreations = ({
|
|
|
58
53
|
// nextPageToken.current = nextPage.nextPage?.token || null;
|
|
59
54
|
nextPageToken.current = token || null;
|
|
60
55
|
setGalleries(
|
|
61
|
-
galleries.map((gallery: IGalleryV2) => new GalleryEntityV2(gallery))
|
|
56
|
+
galleries.map((gallery: galleriesSchema.IGalleryV2) => new GalleryEntityV2(gallery))
|
|
62
57
|
);
|
|
63
58
|
setLoading(false);
|
|
64
59
|
},
|
|
@@ -74,18 +69,18 @@ const useGetUserGalleriesCreations = ({
|
|
|
74
69
|
});
|
|
75
70
|
|
|
76
71
|
const [fetchAssets, { loading: assetsLoading, error: assetsError }] =
|
|
77
|
-
useLazyQuery(FetchAssetsDocument, {
|
|
72
|
+
useLazyQuery(searchSchema.FetchAssetsDocument, {
|
|
78
73
|
context: { uri: hosts.searchHost },
|
|
79
74
|
fetchPolicy: 'no-cache',
|
|
80
75
|
onCompleted: ({ fetchAssets: data }) => {
|
|
81
76
|
setAsset(
|
|
82
77
|
data.map(
|
|
83
|
-
(asset: IAsset) =>
|
|
78
|
+
(asset: assetSchema.IAsset) =>
|
|
84
79
|
new CreationEntity({
|
|
85
80
|
...asset,
|
|
86
81
|
itemType: 'asset',
|
|
87
82
|
itemId: asset.assetId,
|
|
88
|
-
} as unknown as ICreation)
|
|
83
|
+
} as unknown as searchSchema.ICreation)
|
|
89
84
|
)
|
|
90
85
|
);
|
|
91
86
|
setLoading(false);
|
|
@@ -104,13 +99,13 @@ const useGetUserGalleriesCreations = ({
|
|
|
104
99
|
const [
|
|
105
100
|
fetchCollections,
|
|
106
101
|
{ loading: collectionsLoading, error: collectionsError },
|
|
107
|
-
] = useLazyQuery(FetchCollectionsByIdsDocument, {
|
|
102
|
+
] = useLazyQuery(searchSchema.FetchCollectionsByIdsDocument, {
|
|
108
103
|
context: { uri: hosts.searchHost },
|
|
109
104
|
fetchPolicy: 'no-cache',
|
|
110
105
|
onCompleted: ({ fetchCollectionsByIds: data }) => {
|
|
111
106
|
setCollections(
|
|
112
107
|
data.map(
|
|
113
|
-
(collection: ICollectionAsset) =>
|
|
108
|
+
(collection: collectionsSchema.ICollectionAsset) =>
|
|
114
109
|
new CollectionCreationEntity(collection)
|
|
115
110
|
)
|
|
116
111
|
);
|
|
@@ -204,38 +199,3 @@ const useGetUserGalleriesCreations = ({
|
|
|
204
199
|
};
|
|
205
200
|
|
|
206
201
|
export { useGetUserGalleriesCreations };
|
|
207
|
-
|
|
208
|
-
export function getMediaForGallery(
|
|
209
|
-
favorites: GalleryEntityV2[],
|
|
210
|
-
takeFirstFour: boolean
|
|
211
|
-
) {
|
|
212
|
-
if (favorites.length === 0) return { assetArray: [], collectionsArray: [] };
|
|
213
|
-
|
|
214
|
-
const assetArray: unknown[] = [];
|
|
215
|
-
const collectionsArray: unknown[] = [];
|
|
216
|
-
|
|
217
|
-
favorites.forEach((fav: GalleryEntityV2) => {
|
|
218
|
-
const creationIds = takeFirstFour
|
|
219
|
-
? fav.getGalleryCreationIds().slice(0, 4)
|
|
220
|
-
: fav.getGalleryCreationIds();
|
|
221
|
-
|
|
222
|
-
if (!creationIds || creationIds.length === 0) return;
|
|
223
|
-
for (let i = 0; i < creationIds.length; i++) {
|
|
224
|
-
if (creationIds[i].split('.')[0] === 'asset') {
|
|
225
|
-
const assetId = creationIds[i]
|
|
226
|
-
.split('.')
|
|
227
|
-
.splice(1, creationIds[i].length)
|
|
228
|
-
.join('.');
|
|
229
|
-
assetArray.push(assetId);
|
|
230
|
-
} else if (creationIds[i].split('.')[0] === 'collection') {
|
|
231
|
-
const collectionId = creationIds[i]
|
|
232
|
-
.split('.')
|
|
233
|
-
.splice(1, creationIds[i].length)
|
|
234
|
-
.join('.');
|
|
235
|
-
collectionsArray.push(collectionId);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
return { assetArray, collectionsArray };
|
|
241
|
-
}
|