diff --git a/src/discussions/data/hooks.js b/src/discussions/data/hooks.js
index 1fe96a280..1b86eb4d5 100644
--- a/src/discussions/data/hooks.js
+++ b/src/discussions/data/hooks.js
@@ -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) {
diff --git a/src/discussions/data/selectors.js b/src/discussions/data/selectors.js
index 86f3fd9de..cd6da322e 100644
--- a/src/discussions/data/selectors.js
+++ b/src/discussions/data/selectors.js
@@ -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
),
);
diff --git a/src/discussions/discussions-home/DiscussionsHome.jsx b/src/discussions/discussions-home/DiscussionsHome.jsx
index 23b602dd8..06a302b69 100644
--- a/src/discussions/discussions-home/DiscussionsHome.jsx
+++ b/src/discussions/discussions-home/DiscussionsHome.jsx
@@ -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 = () => {
)
)}
- {!enableInContextSidebar && ()}
+ {!enableInContextSidebar && isEnrolled && ()}
{!enableInContextSidebar && }