Skip to content

Commit

Permalink
feat: remove get many collections info (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia authored Nov 15, 2024
1 parent fcbbf94 commit 34bd6cd
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 48 deletions.
12 changes: 0 additions & 12 deletions src/api/itemPublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
DiscriminatedItem,
ItemPublished,
PackedItem,
ResultOf,
UUID,
} from '@graasp/sdk';

Expand All @@ -14,7 +13,6 @@ import {
buildGetPublishedItemsForMemberRoute,
buildItemPublishRoute,
buildItemUnpublishRoute,
buildManyGetItemPublishedInformationsRoute,
} from '../routes.js';
import { PartialQueryConfigForApi } from '../types.js';
import { verifyAuthentication } from './axios.js';
Expand Down Expand Up @@ -69,16 +67,6 @@ export const getItemPublishedInformation = async (
)
.then(({ data }) => data);

export const getManyItemPublishedInformations = async (
ids: UUID[],
{ API_HOST, axios }: PartialQueryConfigForApi,
) =>
axios
.get<
ResultOf<ItemPublished>
>(`${API_HOST}/${buildManyGetItemPublishedInformationsRoute(ids)}`)
.then(({ data }) => data);

export const publishItem = async (
id: UUID,
{ API_HOST, axios }: PartialQueryConfigForApi,
Expand Down
25 changes: 1 addition & 24 deletions src/hooks/itemPublish.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ItemPublished, MAX_TARGETS_FOR_READ_REQUEST, UUID } from '@graasp/sdk';
import { UUID } from '@graasp/sdk';

import { useQuery } from '@tanstack/react-query';

import { splitRequestByIdsAndReturn } from '../api/axios.js';
import * as Api from '../api/itemPublish.js';
import { UndefinedArgument } from '../config/errors.js';
import { itemKeys } from '../keys.js';
Expand Down Expand Up @@ -89,27 +88,5 @@ export default (queryConfig: QueryClientConfig) => {
enabled: enabledValue,
});
},
useManyItemPublishedInformations: (
args: {
itemIds: UUID[];
},
options?: { enabled?: boolean },
) => {
const enabled =
(options?.enabled ?? true) && Boolean(args.itemIds.length);

return useQuery({
queryKey: itemKeys.many(args.itemIds).publishedInformation,
queryFn: () =>
splitRequestByIdsAndReturn<ItemPublished>(
args.itemIds,
MAX_TARGETS_FOR_READ_REQUEST,
(chunk) => Api.getManyItemPublishedInformations(chunk, queryConfig),
true,
),
...defaultQueryOptions,
enabled,
});
},
};
};
9 changes: 0 additions & 9 deletions src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,9 @@ export const itemKeys = {
allMany: () => [...itemKeys.all, 'many'] as const,
many: (ids?: UUID[]) => {
const manyBaseKey = [...itemKeys.allMany(), ids] as const;
const allVisibilities = [...manyBaseKey, 'visibilities'] as const;
return {
// data for the items requested
content: [...manyBaseKey, 'content'],

// children data for the many items requested
children: [...manyBaseKey, 'children'],

// published info
publishedInformation: [...manyBaseKey, 'publishedInformation'],

visibilities: allVisibilities,
};
},

Expand Down
3 changes: 0 additions & 3 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ export const buildItemUnpublishRoute = (itemId: UUID) =>

export const buildGetItemPublishedInformationRoute = (itemId: UUID) =>
`${ITEMS_ROUTE}/${COLLECTIONS_ROUTE}/${itemId}/informations`;
export const buildManyGetItemPublishedInformationsRoute = (itemIds: UUID[]) =>
`${ITEMS_ROUTE}/${COLLECTIONS_ROUTE}/informations?${new URLSearchParams(itemIds.map((id) => ['itemId', id]))}`;
export const buildGetAllPublishedItemsRoute = (categoryIds?: UUID[]) => {
const route = `${ITEMS_ROUTE}/${COLLECTIONS_ROUTE}`;
if (categoryIds && categoryIds.length) {
Expand Down Expand Up @@ -404,7 +402,6 @@ export const API_ROUTES = {
buildImportZipRoute,
buildItemPublishRoute,
buildItemUnpublishRoute,
buildManyGetItemPublishedInformationsRoute,
buildPatchInvitationRoute,
buildPatchItemChatMessageRoute,
buildPatchShortLinkRoute,
Expand Down

0 comments on commit 34bd6cd

Please sign in to comment.