Skip to content

Commit 7482a1c

Browse files
committed
Remove redirect from NewConversation.js, remove clearing data on unmonut, add clearing data to SelectType.js
Clearing data on unmount of NewConveration was causing clearing data on changing route. It was unwanted action, decided to add clear action whenever user hit SelectType route
1 parent b699b7a commit 7482a1c

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

src/pages/NewConversation/NewConversation.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import React, { useEffect } from "react";
1+
import React from "react";
22
import { Redirect, Switch, Route } from "react-router-dom";
3-
import { useDispatch, useSelector } from "react-redux";
43
import { useMediaQuery } from "react-responsive";
54

65
// Components
@@ -11,39 +10,18 @@ import DirectMessage from "./DirectMessageForm/DirectMessageFrom";
1110

1211
// Routes
1312
import {
14-
CONVERSATION_WITHOUT_ID,
1513
NEW_CONVERSATION_GROUP_RECEIVERS,
1614
NEW_CONVERSATION_GROUP_INFO,
1715
NEW_CONVERSATION_DM_RECEIVER,
1816
NEW_CONVERSATION_DM_CONVERSATION,
1917
NEW_CONVERSATION,
2018
} from "../../consts/routes";
2119

22-
// Actions
23-
import { clearNewConversation } from "../../actions/newconversation-actions";
24-
2520
function NewConversation() {
26-
const dispatch = useDispatch();
27-
const conversation = useSelector(
28-
(state) => state.newconversation.conversation
29-
);
30-
3121
const isSmallScreen = useMediaQuery({
3222
query: "(max-width: 1023px)",
3323
});
3424

35-
useEffect(() => {
36-
return () => {
37-
if (conversation) {
38-
dispatch(clearNewConversation());
39-
}
40-
};
41-
}, [dispatch, conversation]);
42-
43-
if (conversation) {
44-
return <Redirect to={`${CONVERSATION_WITHOUT_ID}${conversation._id}`} />;
45-
}
46-
4725
return (
4826
<>
4927
{isSmallScreen ? (

src/pages/NewConversation/SelectType/SelectType.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import { Link, useLocation } from "react-router-dom";
3+
import { useDispatch } from "react-redux";
34

45
// Components
56
import BackLink from "../../../components/BackLink/BackLink";
@@ -9,15 +10,24 @@ import {
910
NEW_CONVERSATION_GROUP_RECEIVERS,
1011
NEW_CONVERSATION_DM_RECEIVER,
1112
} from "../../../consts/routes";
13+
1214
// Assets
1315
import { ReactComponent as NewGroupSVG } from "../../../assets/group.svg";
1416
import { ReactComponent as NewDMSVG } from "../../../assets/plane.svg";
1517

18+
// Actions
19+
import { clearNewConversation } from "../../../actions/newconversation-actions";
20+
1621
// Styles
1722
import classes from "./SelectType.module.scss";
1823

1924
function NewConversationSelectType() {
2025
const location = useLocation();
26+
const dispatch = useDispatch();
27+
useEffect(() => {
28+
// Clear previeous values of new-conversation
29+
dispatch(clearNewConversation());
30+
}, [dispatch]);
2131
return (
2232
<section className={classes.SelectType}>
2333
<BackLink className={classes.Btn} />

0 commit comments

Comments
 (0)