Skip to content

Commit

Permalink
refactor: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Sep 11, 2024
1 parent 395e6f6 commit a9847d2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 63 deletions.
2 changes: 0 additions & 2 deletions src/library-authoring/component-info/ComponentPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Button, StandardModal, useToggle } from '@openedx/paragon';
import { OpenInFull } from '@openedx/paragon/icons';

import { LibraryBlock } from '../LibraryBlock';
import { getXBlockHandlerUrl } from '../data/api';
import { useXBlockRender } from '../data/apiHooks';
import messages from './messages';

// This is a simple overlay to prevent interaction with the preview
Expand Down
39 changes: 0 additions & 39 deletions src/library-authoring/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ export const getLibraryPasteClipboardUrl = (libraryId: string) => `${getApiBaseU
*/
export const getXBlockFieldsApiUrl = (usageKey: string) => `${getApiBaseUrl()}/api/xblock/v2/xblocks/${usageKey}/fields/`;

/**
* Get the URL that render the XBlock in the LMS.
*/
export const getXBlockRenderUrl = (usageKey: string) => `${getApiBaseUrl()}/api/xblock/v2/xblocks/${usageKey}/view/student_view/`;

/**
* Get the URL for the xblock handler API.
* The string `handler_name` is a placeholder for the name of the handler.
*/
export const getXBlockHandlerUrlUrl = (usageKey: string) => `${getApiBaseUrl()}/api/xblock/v2/xblocks/${usageKey}/handler_url/handler_name/`;

export interface ContentLibrary {
id: string;
type: string;
Expand Down Expand Up @@ -144,18 +133,6 @@ export interface UpdateXBlockFieldsRequest {
};
}

export interface XBlockRenderResource {
data: string;
kind: 'url';
mimetype: string;
placement: 'head' | 'foot';
}

export interface XBlockRenderResponse {
content: string;
resources: XBlockRenderResource[];
}

/**
* Fetch block types of a library
*/
Expand Down Expand Up @@ -273,19 +250,3 @@ export async function updateXBlockFields(usageKey:string, xblockData: UpdateXBlo
const client = getAuthenticatedHttpClient();
await client.post(getXBlockFieldsApiUrl(usageKey), xblockData);
}

/**
* Get rendered xblock
*/
export async function getXBlockRender(usageKey: string): Promise<XBlockRenderResponse> {
const { data } = await getAuthenticatedHttpClient().get(getXBlockRenderUrl(usageKey));
return camelCaseObject(data);
}

/**
* Get the URL of the xblock handler.
*/
export const getXBlockHandlerUrl = async (usageKey: string): Promise<string> => {
const { data } = await getAuthenticatedHttpClient().get(getXBlockHandlerUrlUrl(usageKey));
return data.handler_url;
};
22 changes: 0 additions & 22 deletions src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
libraryPasteClipboard,
getXBlockFields,
updateXBlockFields,
getXBlockRender,
} from './api';

const libraryQueryPredicate = (query: Query, libraryId: string): boolean => {
Expand Down Expand Up @@ -53,7 +52,6 @@ export const libraryAuthoringQueryKeys = {
'content',
'libraryBlockTypes',
],
// ToDo: Move to xblockQueryKeys
xblockFields: (contentLibraryId: string, usageKey: string) => [
...libraryAuthoringQueryKeys.contentLibrary(contentLibraryId),
'content',
Expand All @@ -62,18 +60,6 @@ export const libraryAuthoringQueryKeys = {
],
};

export const xblockQueryKeys = {
all: ['xblock'],
/**
* Base key for data specific to a xblock
*/
xblock: (usageKey?: string) => [...xblockQueryKeys.all, usageKey],
render: (usageKey: string) => [
...xblockQueryKeys.xblock(usageKey),
'render',
],
};

/**
* Hook to fetch a content library by its ID.
*/
Expand Down Expand Up @@ -222,11 +208,3 @@ export const useUpdateXBlockFields = (contentLibraryId: string, usageKey: string
},
});
};

export const useXBlockRender = (usageKey: string) => (
useQuery({
queryKey: xblockQueryKeys.render(usageKey),
queryFn: () => getXBlockRender(usageKey),
enabled: !!usageKey,
})
);

0 comments on commit a9847d2

Please sign in to comment.