Merge pull request #41 from edx/kshitij/fix-redirects

fix: fixes issues with redirects [BD-38] [TNL-9387]
This commit is contained in:
Kshitij Sobti
2021-12-28 11:12:43 +00:00
committed by GitHub
3 changed files with 16 additions and 7 deletions

View File

@@ -55,10 +55,11 @@ export default function DiscussionsHome() {
// stored in redirectToThread
if (redirectToThread) {
dispatch(clearRedirect());
history.push(discussionsPath(Routes.COMMENTS.PAGES['my-posts'], {
const newLocation = discussionsPath(Routes.COMMENTS.PAGES['my-posts'], {
courseId,
postId: redirectToThread.threadId,
}));
})(location);
history.push(newLocation);
}
}, [redirectToThread]);
@@ -98,7 +99,13 @@ export default function DiscussionsHome() {
</Route>
<Route path={[Routes.POSTS.PATH, Routes.POSTS.ALL_POSTS]} component={PostsView} />
<Route path={Routes.TOPICS.PATH} component={TopicsView} />
<Redirect from={Routes.DISCUSSIONS.PATH} to={Routes.TOPICS.ALL} />
<Redirect
from={Routes.DISCUSSIONS.PATH}
to={{
...location,
pathname: Routes.TOPICS.ALL,
}}
/>
</Switch>
</div>
<div className={classNames('bg-light-300 flex-column w-75 w-xs-100 w-xl-75', {

View File

@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { Formik } from 'formik';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory, useParams } from 'react-router';
import { useHistory, useLocation, useParams } from 'react-router-dom';
import * as Yup from 'yup';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
@@ -66,6 +66,7 @@ function PostEditor({
const dispatch = useDispatch();
const [submitting, dispatchSubmit] = useDispatchWithState();
const history = useHistory();
const location = useLocation();
const commentsPagePath = useCommentsPagePath();
const {
courseId,
@@ -96,11 +97,12 @@ function PostEditor({
};
const hideEditor = () => {
if (editExisting) {
history.push(discussionsPath(commentsPagePath, {
const newLocation = discussionsPath(commentsPagePath, {
courseId,
topicId,
postId,
}));
})(location);
history.push(newLocation);
}
dispatch(hidePostEditor());
};

View File

@@ -28,7 +28,7 @@ function Post({
const topic = useSelector(selectTopic(post.topicId));
const topicContext = useSelector(selectTopicContext(post.topicId));
const actionHandlers = {
[ContentActions.EDIT_CONTENT]: () => history.push(`${location.pathname}/edit`),
[ContentActions.EDIT_CONTENT]: () => history.push({ ...location, pathname: `${location.pathname}/edit` }),
// TODO: Add flow to confirm before deleting
[ContentActions.DELETE]: () => dispatch(removeThread(post.id)),
[ContentActions.CLOSE]: () => dispatch(updateExistingThread(post.id, { closed: !post.closed })),