fix: deleting a post from sidebar renders entire MFE in the sidebar (#403)

This commit is contained in:
Awais Ansari
2023-01-09 14:35:54 +05:00
committed by GitHub
parent f614c42cc5
commit fd4dbef2e0
2 changed files with 7 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
/* eslint-disable no-param-reassign,import/prefer-default-export */
import { createSlice } from '@reduxjs/toolkit';
import omitBy from 'lodash/omitBy';
import {
PostsStatusFilter, RequestStatus, ThreadOrdering, ThreadType,
@@ -175,7 +176,7 @@ const threadsSlice = createSlice({
state.postStatus = RequestStatus.SUCCESSFUL;
state.threadsInTopic[topicId] = state.threadsInTopic[topicId].filter(item => item !== threadId);
state.pages = state.pages.map(page => page?.filter(item => item !== threadId));
delete state.threadsById[threadId];
state.threadsById = omitBy(state.threadsById, (thread) => thread.id === threadId);
},
deleteThreadFailed: (state) => {
state.postStatus = RequestStatus.FAILED;

View File

@@ -30,6 +30,7 @@ function Post({
const location = useLocation();
const history = useHistory();
const dispatch = useDispatch();
const { enableInContextSidebar } = useContext(DiscussionContext);
const { courseId } = useSelector((state) => state.courseTabs);
const topic = useSelector(selectTopic(post.topicId));
const getTopicSubsection = useSelector(selectorForUnitSubsection);
@@ -49,7 +50,10 @@ function Post({
const handleDeleteConfirmation = () => {
dispatch(removeThread(post.id));
history.push('.');
history.push({
pathname: '.',
search: enableInContextSidebar && '?inContextSidebar',
});
hideDeleteConfirmation();
};
@@ -58,7 +62,6 @@ function Post({
hideReportConfirmation();
};
const { enableInContextSidebar } = useContext(DiscussionContext);
const actionHandlers = {
[ContentActions.EDIT_CONTENT]: () => history.push({
...location,