feat: restricted unnecessary api calls (#683)
* feat: restricted unnecessary api calls * fix: fixed content unavailable issue for user admin * refactor: refactor code for course status
This commit is contained in:
@@ -72,19 +72,22 @@ export const useSidebarVisible = () => {
|
||||
return !hideSidebar;
|
||||
};
|
||||
|
||||
export function useCourseDiscussionData(courseId) {
|
||||
export function useCourseDiscussionData(courseId, isEnrolled) {
|
||||
const dispatch = useDispatch();
|
||||
const { authenticatedUser } = useContext(AppContext);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchBaseData() {
|
||||
await dispatch(fetchCourseConfig(courseId));
|
||||
await dispatch(fetchCourseBlocks(courseId, authenticatedUser.username));
|
||||
await dispatch(fetchTab(courseId));
|
||||
if (isEnrolled) {
|
||||
await dispatch(fetchCourseConfig(courseId));
|
||||
await dispatch(fetchCourseBlocks(courseId, authenticatedUser.username));
|
||||
} else {
|
||||
await dispatch(fetchTab(courseId));
|
||||
}
|
||||
}
|
||||
|
||||
fetchBaseData();
|
||||
}, [courseId]);
|
||||
}, [courseId, isEnrolled]);
|
||||
}
|
||||
|
||||
export function useRedirectToThread(courseId, enableInContextSidebar) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
import selectCourseTabs from '../../components/NavigationBar/data/selectors';
|
||||
import { LOADED } from '../../components/NavigationBar/data/slice';
|
||||
import { PostsStatusFilter, ThreadType } from '../../data/constants';
|
||||
|
||||
export const selectAnonymousPostingConfig = state => ({
|
||||
@@ -69,12 +71,14 @@ export const selectIsUserLearner = createSelector(
|
||||
selectUserIsStaff,
|
||||
selectIsCourseAdmin,
|
||||
selectIsCourseStaff,
|
||||
selectCourseTabs,
|
||||
(
|
||||
userHasModerationPrivileges,
|
||||
userIsGroupTa,
|
||||
userIsStaff,
|
||||
userIsCourseAdmin,
|
||||
userIsCourseStaff,
|
||||
{ courseStatus },
|
||||
) => (
|
||||
(
|
||||
!userHasModerationPrivileges
|
||||
@@ -82,6 +86,7 @@ export const selectIsUserLearner = createSelector(
|
||||
&& !userIsStaff
|
||||
&& !userIsCourseAdmin
|
||||
&& !userIsCourseStaff
|
||||
&& courseStatus === LOADED
|
||||
) || false
|
||||
),
|
||||
);
|
||||
|
||||
@@ -58,7 +58,7 @@ const DiscussionsHome = () => {
|
||||
courseId, postId, topicId, category, learnerUsername,
|
||||
} = params;
|
||||
|
||||
useCourseDiscussionData(courseId);
|
||||
useCourseDiscussionData(courseId, isEnrolled);
|
||||
useRedirectToThread(courseId, enableInContextSidebar);
|
||||
useFeedbackWrapper();
|
||||
/* Display the content area if we are currently viewing/editing a post or creating one.
|
||||
@@ -172,7 +172,7 @@ const DiscussionsHome = () => {
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
{!enableInContextSidebar && (<DiscussionsProductTour />)}
|
||||
{!enableInContextSidebar && isEnrolled && (<DiscussionsProductTour />)}
|
||||
</main>
|
||||
{!enableInContextSidebar && <Footer />}
|
||||
</DiscussionContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user