Improving file organization.
This commit is contained in:
11
src/learning-sequence/sub-section/data/api.js
Normal file
11
src/learning-sequence/sub-section/data/api.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
|
||||
export async function getSubSectionMetadata(courseId, subSectionId) {
|
||||
const { data } = await getAuthenticatedHttpClient()
|
||||
.get(`${getConfig().LMS_BASE_URL}/courses/${courseId}/xblock/${subSectionId}/handler/xmodule_handler/metadata`, {});
|
||||
|
||||
return data;
|
||||
}
|
||||
31
src/learning-sequence/sub-section/data/hooks.js
Normal file
31
src/learning-sequence/sub-section/data/hooks.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import { getSubSectionMetadata } from './api';
|
||||
|
||||
export function useSubSectionMetadata(courseId, subSectionId) {
|
||||
const [metadata, setMetadata] = useState(null);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setLoaded(false);
|
||||
getSubSectionMetadata(courseId, subSectionId).then((data) => {
|
||||
setMetadata(data);
|
||||
setLoaded(true);
|
||||
});
|
||||
}, [courseId, subSectionId]);
|
||||
|
||||
return {
|
||||
metadata,
|
||||
loaded,
|
||||
};
|
||||
}
|
||||
|
||||
export function useExamRedirect(metadata, blocks) {
|
||||
useEffect(() => {
|
||||
if (metadata !== null && blocks !== null) {
|
||||
if (metadata.isTimeLimited) {
|
||||
global.location.href = blocks[metadata.itemId].lmsWebUrl;
|
||||
}
|
||||
}
|
||||
}, [metadata, blocks]);
|
||||
}
|
||||
Reference in New Issue
Block a user