diff --git a/src/library-authoring/data/api.js b/src/library-authoring/data/api.js index ff0dd3dec5..faebcb12f9 100644 --- a/src/library-authoring/data/api.js +++ b/src/library-authoring/data/api.js @@ -1,12 +1,21 @@ // @ts-check -import type { ContentLibrary } from './types'; import { camelCaseObject, getConfig } from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; -const getApiBaseUrl = (): string => getConfig().STUDIO_BASE_URL; -const getContentLibraryApiUrl = (libraryId: string) => `${getApiBaseUrl()}/api/libraries/v2/${libraryId}/`; +const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; +/** + * Get the URL for the content library API. + * @param {string} libraryId - The ID of the library to fetch. + */ +const getContentLibraryApiUrl = (libraryId) => `${getApiBaseUrl()}/api/libraries/v2/${libraryId}/`; -export async function getContentLibrary(libraryId: string): Promise { +/** + * Fetch a content library by its ID. + * @param {string} [libraryId] - The ID of the library to fetch. + * @returns {Promise} + */ +/* eslint-disable import/prefer-default-export */ +export async function getContentLibrary(libraryId) { const { data } = await getAuthenticatedHttpClient().get(getContentLibraryApiUrl(libraryId)); return camelCaseObject(data); } diff --git a/src/library-authoring/data/apiHook.js b/src/library-authoring/data/apiHook.js index 53509fbe3b..8f11e49a4e 100644 --- a/src/library-authoring/data/apiHook.js +++ b/src/library-authoring/data/apiHook.js @@ -1,5 +1,5 @@ // @ts-check -import React, { useEffect } from 'react'; +import React from 'react'; import { useQuery } from '@tanstack/react-query'; import { MeiliSearch } from 'meilisearch'; @@ -8,24 +8,21 @@ import { getContentLibrary } from './api'; /** * Hook to fetch a content library by its ID. + * @param {string} [libraryId] - The ID of the library to fetch. */ -export const useContentLibrary = (libraryId?: string) => { - if (!libraryId) { - return { - data: undefined, - error: 'No library ID provided', - isLoading: false, - } - } - - return useQuery({ +export const useContentLibrary = (libraryId) => ( + useQuery({ queryKey: ['contentLibrary', libraryId], queryFn: () => getContentLibrary(libraryId), - }); -}; - + }) +); -export const useLibraryComponentCount = (libraryId: string, searchKeywords: string) => { +/** + * Hook to fetch the count of components and collections in a library. + * @param {string} libraryId - The ID of the library to fetch. + * @param {string} searchKeywords - Keywords to search for. + */ +export const useLibraryComponentCount = (libraryId, searchKeywords) => { // Meilisearch code to get Collection and Component counts const { data: connectionDetails } = useContentSearchConnection(); @@ -52,6 +49,4 @@ export const useLibraryComponentCount = (libraryId: string, searchKeywords: stri componentCount, collectionCount, }; -} - - +}; diff --git a/src/library-authoring/data/types.js b/src/library-authoring/data/types.js deleted file mode 100644 index 1af41a8b1f..0000000000 --- a/src/library-authoring/data/types.js +++ /dev/null @@ -1,17 +0,0 @@ -export type ContentLibrary = { - id: string; - type: string; - org: string; - slug: string; - title: string; - description: string; - numBlocks: number; - version: number; - lastPublished: Date | null; - allowLti: boolean; - allowPublicLearning: boolean; - allowPublicRead: boolean; - hasUnpublishedChanges: boolean; - hasUnpublishedDeletes: boolean; - license: string; -} diff --git a/src/library-authoring/data/types.mjs b/src/library-authoring/data/types.mjs new file mode 100644 index 0000000000..34486525d7 --- /dev/null +++ b/src/library-authoring/data/types.mjs @@ -0,0 +1,18 @@ +/** + * @typedef {Object} ContentLibrary + * @property {string} id + * @property {string} type + * @property {string} org + * @property {string} slug + * @property {string} title + * @property {string} description + * @property {number} numBlocks + * @property {number} version + * @property {Date | null} lastPublished + * @property {boolean} allowLti + * @property {boolean} allowPublicLearning + * @property {boolean} allowPublicRead + * @property {boolean} hasUnpublishedChanges + * @property {boolean} hasUnpublishedDeletes + * @property {string} license + */