pathName 가져오기
loadTalkRoomListToAxios()
를 dispatch 했다.// chat 보냈을 때 채팅방에 둘다 있을 때 타입 0
// chat 보냈을 때 채팅방에 한명만 있고 상대방은 로그인 했을 때 타입 1
// chat 보냈을 때 상대방이 로그아웃 타입 2
// tap 요청 받았을 때 타입 3
// tap 요청 거절한게 타입 4
// tap 요청 수락한게 타입 5
if (newNoti.type === 1) {
console.log('채팅알람!');
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
dispatch(setChatNoti(true));
}
user B가 /grabtalk 페이지에 있을 때만 dispatch를 하면 될 것 같아서 코드를 수정 했다.
const pageCheck = window.location.pathname;
if (newNoti.type === 1) {
if (pageCheck === '/grabtalk') {
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
}
dispatch(setChatNoti(true));
}
정상적으로 동작 하길래 이것저것 더 테스트를 해보던 중 메인페이지로 돌아갔다가 채팅페이지로 오게 되면 pathname이 날아가서 미리보기가 갱신 되지 않는 문제점을 발견 했다.
그래서 url을 가지고 오는 몇가지 방법을 더 시도해 보았다.
import { useHistory, useLocation } from 'react-router-dom';
const history = useHistory();
const location = useLocation();
const pageCheck = window.location.href.split('/');
const nowPage = pageCheck[pageCheck.length - 1];
const nowPageE = window.location.pathname;
if (newNoti.type === 1) {
console.log(
'nowPageE = window.location.pathname ===>',
nowPageE,
);
console.log('location ====>', location);
console.log('history ====>', history);
console.log('nowPage ====>', nowPage);
console.log(
'pageCheck = window.location.href.split("/") ====>',
pageCheck,
);
if (nowPage === '/grabtalk') {
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
}
dispatch(setChatNoti(true));
}
const nowPage = history.location.pathname;
if (newNoti.type === 1) {
console.log('history.location.pathname ====>', nowPage);
console.log('history ====>', history);
if (nowPage === '/grabtalk') {
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
}
dispatch(setChatNoti(true));
}
if (newNoti.type === 1) {
if (history.location.pathname === '/grabtalk') {
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
}
dispatch(setChatNoti(true));
}