Skip to content

Commit

Permalink
fix: now content unavailable ui is only for learner (#672)
Browse files Browse the repository at this point in the history
Co-authored-by: Awais Ansari <79941147+awais-ansari@users.noreply.github.com>
  • Loading branch information
sundasnoreen12 and awais-ansari authored Feb 27, 2024
1 parent 8fc6665 commit 6875165
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/NavigationBar/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const slice = createSlice({
tabs: [],
courseTitle: null,
courseNumber: null,
isEnrolled: false,
org: null,
},
reducers: {
Expand Down
23 changes: 23 additions & 0 deletions src/discussions/data/selectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createSelector } from '@reduxjs/toolkit';

import { PostsStatusFilter, ThreadType } from '../../data/constants';

export const selectAnonymousPostingConfig = state => ({
Expand Down Expand Up @@ -60,3 +62,24 @@ export function selectTopicThreadCount(topicId) {
export function selectPostThreadCount(state) {
return state.threads.totalThreads;
}

export const selectIsUserLearner = createSelector(
selectUserHasModerationPrivileges,
selectUserIsGroupTa,
selectUserIsStaff,
selectIsCourseAdmin,
selectIsCourseStaff,
(
userHasModerationPrivileges,
userIsGroupTa,
userIsStaff,
userIsCourseAdmin,
userIsCourseStaff,
) => (
!userHasModerationPrivileges
&& !userIsGroupTa
&& !userIsStaff
&& !userIsCourseAdmin
&& !userIsCourseStaff
),
);
11 changes: 6 additions & 5 deletions src/discussions/discussions-home/DiscussionsHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { LearningHeader as Header } from '@edx/frontend-component-header';

import { Spinner } from '../../components';
import selectCourseTabs from '../../components/NavigationBar/data/selectors';
import { LOADED } from '../../components/NavigationBar/data/slice';
import { LOADING } from '../../components/NavigationBar/data/slice';
import { ALL_ROUTES, DiscussionProvider, Routes as ROUTES } from '../../data/constants';
import DiscussionContext from '../common/context';
import ContentUnavailable from '../course-content-unavailable/CourseContentUnavailable';
import {
useCourseDiscussionData, useIsOnDesktop, useRedirectToThread, useSidebarVisible,
} from '../data/hooks';
import { selectDiscussionProvider, selectEnableInContext } from '../data/selectors';
import { selectDiscussionProvider, selectEnableInContext, selectIsUserLearner } from '../data/selectors';
import { EmptyLearners, EmptyTopics } from '../empty-posts';
import EmptyPosts from '../empty-posts/EmptyPosts';
import { EmptyTopic as InContextEmptyTopics } from '../in-context-topics/components';
Expand All @@ -46,6 +46,7 @@ const DiscussionsHome = () => {
const {
courseNumber, courseTitle, org, courseStatus, isEnrolled,
} = useSelector(selectCourseTabs);
const isUserLearner = useSelector(selectIsUserLearner);
const pageParams = useMatch(ROUTES.COMMENTS.PAGE)?.params;
const page = pageParams?.page || null;
const matchPattern = ALL_ROUTES.find((route) => matchPath({ path: route }, location.pathname));
Expand Down Expand Up @@ -84,7 +85,7 @@ const DiscussionsHome = () => {
)}
<main className="container-fluid d-flex flex-column p-0 w-100" id="main" tabIndex="-1">
{!enableInContextSidebar && <CourseTabsNavigation activeTab="discussion" courseId={courseId} />}
{(isEnrolled || enableInContextSidebar) && (
{(isEnrolled || !isUserLearner || enableInContextSidebar) && (
<div
className={classNames('header-action-bar bg-white position-sticky', {
'shadow-none border-light-300 border-bottom': enableInContextSidebar,
Expand Down Expand Up @@ -125,9 +126,9 @@ const DiscussionsHome = () => {
</Routes>
</Suspense>
)}
{(courseStatus === LOADED || enableInContextSidebar) && (
{(courseStatus !== LOADING || enableInContextSidebar) && (
<div>
{ isEnrolled === false ? (
{ isEnrolled === false && isUserLearner ? (
<Suspense fallback={(<Spinner />)}>
<Routes>
{ALL_ROUTES.map((route) => (
Expand Down

0 comments on commit 6875165

Please sign in to comment.