Skip to content

Commit

Permalink
fix: [AXIMST-424] Course unit - Fixed network connection behavior (#138)
Browse files Browse the repository at this point in the history
* fix: [AXIMST-424] fixed network connetcion behavior

* fix: added placeholder for unsuccessful loading for the page

* refactor: code refactoring
  • Loading branch information
PKulkoRaccoonGang committed Mar 10, 2024
1 parent cdd3118 commit 713ca4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/course-unit/CourseUnit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import getPageHeadTitle from '../generic/utils';
import AlertMessage from '../generic/alert-message';
import ProcessingNotification from '../generic/processing-notification';
import InternetConnectionAlert from '../generic/internet-connection-alert';
import ConnectionErrorAlert from '../generic/ConnectionErrorAlert';
import Loading from '../generic/Loading';
import AddComponent from './add-component/AddComponent';
import CourseXBlock from './course-xblock/CourseXBlock';
Expand All @@ -32,6 +33,7 @@ const CourseUnit = ({ courseId }) => {
sequenceId,
unitTitle,
isQueryPending,
sequenceStatus,
savingStatus,
isTitleEditFormOpen,
isErrorAlert,
Expand All @@ -57,6 +59,14 @@ const CourseUnit = ({ courseId }) => {
return <Loading />;
}

if (sequenceStatus === RequestStatus.FAILED) {
return (

Check warning on line 63 in src/course-unit/CourseUnit.jsx

View check run for this annotation

Codecov / codecov/patch

src/course-unit/CourseUnit.jsx#L63

Added line #L63 was not covered by tests
<Container size="xl" className="course-unit px-4 mt-4">
<ConnectionErrorAlert />
</Container>
);
}

return (
<>
<Container size="xl" className="course-unit px-4">
Expand Down
7 changes: 3 additions & 4 deletions src/course-unit/data/selectors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export const getCourseUnitData = (state) => state.courseUnit.unit;
export const getCourseUnit = (state) => state.courseUnit;
export const getSavingStatus = (state) => state.courseUnit.savingStatus;
export const getLoadingStatus = (state) => state.courseUnit.loadingStatus;
export const getSequenceStatus = (state) => state.courseUnit.sequenceStatus;
export const getSequenceIds = (state) => state.courseUnit.courseSectionVertical.courseSequenceIds;
export const getCourseSectionVertical = (state) => state.courseUnit.courseSectionVertical;
export const getCourseId = state => state.courseDetail.courseId;
export const getSequenceId = state => state.courseUnit.sequenceId;
export const getCourseVerticalChildren = state => state.courseUnit.courseVerticalChildren;
export const getCourseId = (state) => state.courseDetail.courseId;
export const getSequenceId = (state) => state.courseUnit.sequenceId;
export const getCourseVerticalChildren = (state) => state.courseUnit.courseVerticalChildren;
5 changes: 4 additions & 1 deletion src/course-unit/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getCourseUnitData,
getLoadingStatus,
getSavingStatus,
getSequenceStatus,
} from './data/selectors';
import { changeEditTitleFormOpen, updateQueryPendingStatus } from './data/slice';

Expand All @@ -30,6 +31,7 @@ export const useCourseUnit = ({ courseId, blockId }) => {
const courseUnit = useSelector(getCourseUnitData);
const savingStatus = useSelector(getSavingStatus);
const loadingStatus = useSelector(getLoadingStatus);
const sequenceStatus = useSelector(getSequenceStatus);
const { draftPreviewLink, publishedPreviewLink } = useSelector(getCourseSectionVertical);
const courseVerticalChildren = useSelector(getCourseVerticalChildren);
const navigate = useNavigate();
Expand Down Expand Up @@ -86,7 +88,7 @@ export const useCourseUnit = ({ courseId, blockId }) => {

useEffect(() => {
if (savingStatus === RequestStatus.SUCCESSFUL) {
dispatch(updateQueryPendingStatus(false));
dispatch(updateQueryPendingStatus(true));
} else if (savingStatus === RequestStatus.FAILED && !hasInternetConnectionError) {
toggleErrorAlert(true);
}
Expand All @@ -104,6 +106,7 @@ export const useCourseUnit = ({ courseId, blockId }) => {
sequenceId,
courseUnit,
unitTitle,
sequenceStatus,
savingStatus,
isQueryPending,
isErrorAlert,
Expand Down

0 comments on commit 713ca4b

Please sign in to comment.