Skip to content

Commit

Permalink
fix: type and lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Jun 6, 2024
1 parent d853f29 commit d212fa9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
17 changes: 13 additions & 4 deletions src/library-authoring/data/api.js
Original file line number Diff line number Diff line change
@@ -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<ContentLibrary> {
/**
* Fetch a content library by its ID.
* @param {string} [libraryId] - The ID of the library to fetch.
* @returns {Promise<import("./types.mjs").ContentLibrary>}
*/
/* eslint-disable import/prefer-default-export */
export async function getContentLibrary(libraryId) {
const { data } = await getAuthenticatedHttpClient().get(getContentLibraryApiUrl(libraryId));

Check failure on line 19 in src/library-authoring/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
return camelCaseObject(data);
}
31 changes: 13 additions & 18 deletions src/library-authoring/data/apiHook.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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();

Expand All @@ -52,6 +49,4 @@ export const useLibraryComponentCount = (libraryId: string, searchKeywords: stri
componentCount,
collectionCount,
};
}


};
17 changes: 0 additions & 17 deletions src/library-authoring/data/types.js

This file was deleted.

18 changes: 18 additions & 0 deletions src/library-authoring/data/types.mjs
Original file line number Diff line number Diff line change
@@ -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
*/

0 comments on commit d212fa9

Please sign in to comment.