Improving file organization.

This commit is contained in:
David Joy
2020-01-10 11:52:37 -05:00
parent 0db7cabf29
commit 990cef31a3
12 changed files with 162 additions and 400 deletions

View 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;
}

View 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]);
}