diff --git a/src/course-unit/CourseUnit.jsx b/src/course-unit/CourseUnit.jsx index 04ac848618..3af7448ba9 100644 --- a/src/course-unit/CourseUnit.jsx +++ b/src/course-unit/CourseUnit.jsx @@ -142,7 +142,7 @@ const CourseUnit = ({ courseId }) => { )} {staticFileNotices && ( )} diff --git a/src/course-unit/course-sequence/Sequence.jsx b/src/course-unit/course-sequence/Sequence.jsx index 4f9c371c65..f405e07fa4 100644 --- a/src/course-unit/course-sequence/Sequence.jsx +++ b/src/course-unit/course-sequence/Sequence.jsx @@ -1,4 +1,3 @@ -import { useEffect } from 'react'; import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import classNames from 'classnames'; @@ -22,16 +21,6 @@ const Sequence = ({ const shouldDisplayNotificationTriggerInSequence = useWindowSize().width < breakpoints.small.minWidth; const { sequenceStatus, sequenceMightBeUnit } = useSelector(state => state.courseUnit); - useEffect(() => { - const staticFileNotices = localStorage.getItem('staticFileNotices'); - - return () => { - if (staticFileNotices) { - localStorage.removeItem('staticFileNotices'); - } - }; - }, []); - const defaultContent = (
diff --git a/src/course-unit/data/selectors.js b/src/course-unit/data/selectors.js index 77f948dcf0..8979ec3c13 100644 --- a/src/course-unit/data/selectors.js +++ b/src/course-unit/data/selectors.js @@ -1,5 +1,6 @@ export const getCourseUnitData = (state) => state.courseUnit.unit; export const getCanEdit = (state) => state.courseUnit.canEdit; +export const getStaticFileNotices = (state) => state.courseUnit.staticFileNotices; export const getSavingStatus = (state) => state.courseUnit.savingStatus; export const getLoadingStatus = (state) => state.courseUnit.loadingStatus; export const getSequenceStatus = (state) => state.courseUnit.sequenceStatus; diff --git a/src/course-unit/data/slice.js b/src/course-unit/data/slice.js index a906ed3787..31be91ddd7 100644 --- a/src/course-unit/data/slice.js +++ b/src/course-unit/data/slice.js @@ -19,6 +19,7 @@ const slice = createSlice({ courseSectionVertical: {}, courseVerticalChildren: {}, clipboardData: null, + staticFileNotices: {}, }, reducers: { fetchCourseItemSuccess: (state, { payload }) => { @@ -100,6 +101,9 @@ const slice = createSlice({ updateClipboardData: (state, { payload }) => { state.clipboardData = payload; }, + fetchStaticFileNoticesSuccess: (state, { payload }) => { + state.staticFileNotices = payload; + }, reorderXBlockList: (state, { payload }) => { // Create a map for payload IDs to their index for O(1) lookups const indexMap = new Map(payload.map((id, index) => [id, index])); @@ -129,6 +133,7 @@ export const { deleteXBlock, duplicateXBlock, updateClipboardData, + fetchStaticFileNoticesSuccess, reorderXBlockList, } = slice.actions; diff --git a/src/course-unit/data/thunk.js b/src/course-unit/data/thunk.js index 8b8cdf274f..2c91c6f01d 100644 --- a/src/course-unit/data/thunk.js +++ b/src/course-unit/data/thunk.js @@ -38,6 +38,7 @@ import { updateQueryPendingStatus, deleteXBlock, duplicateXBlock, + fetchStaticFileNoticesSuccess, reorderXBlockList, } from './slice'; import { getNotificationMessage } from './utils'; @@ -75,6 +76,8 @@ export function fetchCourseSectionVerticalData(courseId, sequenceId) { modelType: 'units', models: courseSectionVerticalData.units, })); + dispatch(fetchStaticFileNoticesSuccess(JSON.parse(localStorage.getItem('staticFileNotices')))); + localStorage.removeItem('staticFileNotices'); dispatch(updateClipboardData(courseSectionVerticalData.userClipboard)); dispatch(fetchSequenceSuccess({ sequenceId })); return true; diff --git a/src/course-unit/hooks.jsx b/src/course-unit/hooks.jsx index 8a8f412343..da6320cc96 100644 --- a/src/course-unit/hooks.jsx +++ b/src/course-unit/hooks.jsx @@ -21,6 +21,7 @@ import { getLoadingStatus, getSavingStatus, getSequenceStatus, + getStaticFileNotices, getCanEdit, } from './data/selectors'; import { changeEditTitleFormOpen, updateQueryPendingStatus } from './data/slice'; @@ -40,7 +41,7 @@ export const useCourseUnit = ({ courseId, blockId }) => { const sequenceStatus = useSelector(getSequenceStatus); const { draftPreviewLink, publishedPreviewLink } = useSelector(getCourseSectionVertical); const courseVerticalChildren = useSelector(getCourseVerticalChildren); - const staticFileNotices = localStorage.getItem('staticFileNotices'); + const staticFileNotices = useSelector(getStaticFileNotices); const navigate = useNavigate(); const isEditTitleFormOpen = useSelector(state => state.courseUnit.isEditTitleFormOpen); const isQueryPending = useSelector(state => state.courseUnit.isQueryPending); @@ -105,12 +106,6 @@ export const useCourseUnit = ({ courseId, blockId }) => { dispatch(setXBlockOrderListQuery(blockId, xblockListIds, restoreCallback)); }; - useEffect(() => { - if (staticFileNotices) { - localStorage.removeItem('staticFileNotices'); - } - }, []); - useEffect(() => { if (savingStatus === RequestStatus.SUCCESSFUL) { dispatch(updateQueryPendingStatus(true));