From 2ed5aee9e73b831b38c67e13891e967b9b9a1c5c Mon Sep 17 00:00:00 2001 From: Kshitij Sobti Date: Thu, 9 Dec 2021 23:59:35 +0530 Subject: [PATCH] fix: fixes issues with redirects Currently redirecting doesn't preserve query parameters. This change fixes this and fixes all usages of history.push --- .../discussions-home/DiscussionsHome.jsx | 13 ++++++++++--- src/discussions/posts/post-editor/PostEditor.jsx | 8 +++++--- src/discussions/posts/post/Post.jsx | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/discussions/discussions-home/DiscussionsHome.jsx b/src/discussions/discussions-home/DiscussionsHome.jsx index 0db64ffe..2ae61262 100644 --- a/src/discussions/discussions-home/DiscussionsHome.jsx +++ b/src/discussions/discussions-home/DiscussionsHome.jsx @@ -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() { - +
{ if (editExisting) { - history.push(discussionsPath(commentsPagePath, { + const newLocation = discussionsPath(commentsPagePath, { courseId, topicId, postId, - })); + })(location); + history.push(newLocation); } dispatch(hidePostEditor()); }; diff --git a/src/discussions/posts/post/Post.jsx b/src/discussions/posts/post/Post.jsx index 5eee92fc..7514d59d 100644 --- a/src/discussions/posts/post/Post.jsx +++ b/src/discussions/posts/post/Post.jsx @@ -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 })),