-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: handle unsaved changes in text & problem editors #1444
Changes from all commits
78b513b
c8f512c
0819a60
c620d5b
aaa2345
0c5079e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { | |
} from '@openedx/paragon'; | ||
import { EditOutline as EditIcon, MoreVert as MoveVertIcon } from '@openedx/paragon/icons'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { useNavigate, useSearchParams } from 'react-router-dom'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
import { getCanEdit, getCourseId } from 'CourseAuthoring/course-unit/data/selectors'; | ||
import DeleteModal from '../../generic/delete-modal/DeleteModal'; | ||
|
@@ -19,6 +19,7 @@ import { copyToClipboard } from '../../generic/data/thunks'; | |
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants'; | ||
import XBlockMessages from './xblock-messages/XBlockMessages'; | ||
import messages from './messages'; | ||
import { createCorrectInternalRoute } from '../../utils'; | ||
|
||
const CourseXBlock = ({ | ||
id, title, type, unitXBlockActions, shouldScroll, userPartitionInfo, | ||
|
@@ -28,7 +29,6 @@ const CourseXBlock = ({ | |
const [isDeleteModalOpen, openDeleteModal, closeDeleteModal] = useToggle(false); | ||
const [isConfigureModalOpen, openConfigureModal, closeConfigureModal] = useToggle(false); | ||
const dispatch = useDispatch(); | ||
const navigate = useNavigate(); | ||
const canEdit = useSelector(getCanEdit); | ||
const courseId = useSelector(getCourseId); | ||
const intl = useIntl(); | ||
|
@@ -58,7 +58,11 @@ const CourseXBlock = ({ | |
case COMPONENT_TYPES.html: | ||
case COMPONENT_TYPES.problem: | ||
case COMPONENT_TYPES.video: | ||
navigate(`/course/${courseId}/editor/${type}/${id}`); | ||
// Not using useNavigate from react router to use browser navigation | ||
// which allows us to block back button if unsaved changes in editor are present. | ||
window.location.assign( | ||
createCorrectInternalRoute(`/course/${courseId}/editor/${type}/${id}`), | ||
); | ||
Comment on lines
+61
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the part that replaces use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to implement with react-router if you want, though: https://reactrouter.com/en/main/hooks/use-blocker There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bradenmacdonald I did try it out but it has some issues as mentioned in the description:
@rpenido also tried it out with same results. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry I missed that. Thanks for investigating it. |
||
break; | ||
default: | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended?
Not a problem, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was checking if
useBlocker
is fixed in the latest version and then left it as is.