add refresh for contact
Change-Id: Ie0105760ebda96463e8a112b459b7de014d79110
diff --git a/client/src/pages/addContactPage.jsx b/client/src/pages/addContactPage.jsx
index e47ed95..96d7bdc 100644
--- a/client/src/pages/addContactPage.jsx
+++ b/client/src/pages/addContactPage.jsx
@@ -4,11 +4,15 @@
import { Box, Container, Fab, Card, CardContent, Typography } from '@mui/material';
import GroupAddRounded from '@mui/icons-material/GroupAddRounded';
import authManager from '../AuthManager'
+import { useAppDispatch } from '../../redux/hooks';
+import { setRefreshFromSlice } from '../../redux/appSlice';
+
export default function AddContactPage(props) {
const navigate = useNavigate();
const accountId = props.accountId || props.match.params.accountId
const contactId = props.contactId || props.match.params.contactId
+ const dispatch = useAppDispatch();
const handleClick = async e => {
const response = await authManager.fetch(`/api/accounts/${accountId}/conversations`, {
@@ -18,7 +22,10 @@
'Content-Type': 'application/json'
},
body: JSON.stringify({members:[contactId]})
- }).then(res => res.json())
+ }).then(res => {
+ dispatch(setRefreshFromSlice())
+ return res.json()
+ })
console.log(response)
if (response.conversationId) {
diff --git a/client/src/pages/messenger.jsx b/client/src/pages/messenger.jsx
index 84a4dc5..ea64d9b 100644
--- a/client/src/pages/messenger.jsx
+++ b/client/src/pages/messenger.jsx
@@ -12,8 +12,12 @@
import LoadingPage from '../components/loading';
import { useParams } from 'react-router';
import { Stack } from '@mui/material';
+import { useAppSelector } from '../../redux/hooks';
+
const Messenger = (props) => {
+ const { refresh } = useAppSelector((state) => state.app);
+
const [conversations, setConversations] = useState(undefined)
const [searchQuery, setSearchQuery] = useState('')
const [searchResult, setSearchResults] = useState(undefined)
@@ -24,6 +28,7 @@
const contactId = props.contactId || params.contactId
useEffect(() => {
+ console.log("REFRESH CONVERSATIONS FROM MESSENGER")
const controller = new AbortController()
authManager.fetch(`/api/accounts/${accountId}/conversations`, {signal: controller.signal})
.then(res => res.json())
@@ -31,8 +36,8 @@
console.log(result)
setConversations(Object.values(result).map(c => Conversation.from(accountId, c)))
})
- // return () => controller.abort() // crash on React18
- }, [accountId])
+ // return () => controller.abort()
+ }, [accountId, refresh])
useEffect(() => {
if (!searchQuery)