From 0bd23a7e99b046e6fa85cd7406dd463e379ad4b5 Mon Sep 17 00:00:00 2001 From: HyunJungJo98 Date: Sun, 27 Mar 2022 20:27:25 +0900 Subject: [PATCH] =?UTF-8?q?[#57]Refactor:=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/DMPage/DMDetail.js | 11 ++++--- .../src/components/DMPage/DMList.js | 18 +--------- .../src/components/DMPage/DMListThumbnail.js | 32 ++++++++++++++---- .../src/components/DMPage/DMPage.js | 33 +++++++++++++++++-- .../TransactionPage/TransactionDetail.js | 13 ++++---- 5 files changed, 71 insertions(+), 36 deletions(-) diff --git a/frontend/sweet-red-beans/src/components/DMPage/DMDetail.js b/frontend/sweet-red-beans/src/components/DMPage/DMDetail.js index 825e9a0..396cfdc 100644 --- a/frontend/sweet-red-beans/src/components/DMPage/DMDetail.js +++ b/frontend/sweet-red-beans/src/components/DMPage/DMDetail.js @@ -25,6 +25,7 @@ let stompClient = null; //transaction_id 값 바꾸기 const DMDetail = ({ selectedRoom }) => { const navigation = useNavigate(); + const cookies = new Cookies(); const [modalOpen, setModalOpen] = useState(false); @@ -36,7 +37,8 @@ const DMDetail = ({ selectedRoom }) => { const [imgFile, setImgFile] = useState(null); const [imgBase64, setImgBase64] = useState(null); - const [myNickname, setMyNickname] = useState(''); + const [myNickname, setMyNickname] = useState(cookies.get('user').nickname); + const [userStatus, setUserStatus] = useState(null); const openModal = () => { setModalOpen(true); @@ -84,6 +86,7 @@ const DMDetail = ({ selectedRoom }) => { ); }); setComplete(selectedRoom.is_complete); + setUserStatus(selectedRoom.not_mine_user_status); return () => { if (stompClient != null) { @@ -271,15 +274,13 @@ const DMDetail = ({ selectedRoom }) => {
- {selectedRoom.user_status === '정지' || - selectedRoom.user_status === '탈퇴' + {userStatus === '정지' || userStatus === '탈퇴' ? '(알수없음)' : selectedRoom.not_mine_nickname}
diff --git a/frontend/sweet-red-beans/src/components/DMPage/DMList.js b/frontend/sweet-red-beans/src/components/DMPage/DMList.js index f716ec2..d7788c9 100644 --- a/frontend/sweet-red-beans/src/components/DMPage/DMList.js +++ b/frontend/sweet-red-beans/src/components/DMPage/DMList.js @@ -7,24 +7,8 @@ import { SELECTED_DM } from '../../actions/types'; import { useNavigate } from 'react-router'; import style from '../../css/DMPage/DMList.module.css'; -const DMList = () => { +const DMList = ({ DMlist }) => { const dispatch = useDispatch(); - const [DMlist, setDMList] = useState([]); - useEffect(() => { - //DM 목록 조회 - axios - .get('http://localhost:8080/direct-message', { - withCredentials: true, - }) - .then((response) => { - setDMList(response.data.room_id); - }) - .catch((error) => {}); - - return () => { - setDMList(null); - }; - }, []); const DMListClick = (selectedRoom, e) => { dispatch({ diff --git a/frontend/sweet-red-beans/src/components/DMPage/DMListThumbnail.js b/frontend/sweet-red-beans/src/components/DMPage/DMListThumbnail.js index 145f625..d42cd3e 100644 --- a/frontend/sweet-red-beans/src/components/DMPage/DMListThumbnail.js +++ b/frontend/sweet-red-beans/src/components/DMPage/DMListThumbnail.js @@ -14,13 +14,33 @@ const DMListThumbnail = ({ dm }) => { if (s === undefined) { return null; } else { - return s.selectedRoom; + if (s.selectedRoom !== undefined) { + return s.selectedRoom; + } else if (s.DMCreate !== undefined) { + return s.DMCreate; + } else { + return null; + } } }); + console.log(selectedRoomId); + useEffect(() => { + if (selectedRoomId !== null) { + if (dm.chat_room_id === selectedRoomId.chat_room_id) { + console.log(dm); + console.log('현재 : ', selectedRoomId); + setCurrentRoom(true); + } else { + setCurrentRoom(false); + } + } + }, []); useEffect(() => { if (selectedRoomId !== null) { if (dm.chat_room_id === selectedRoomId.chat_room_id) { + console.log(dm); + console.log('현재 : ', selectedRoomId); setCurrentRoom(true); } else { setCurrentRoom(false); @@ -33,7 +53,8 @@ const DMListThumbnail = ({ dm }) => {
{
- {dm.user_status === '정지' || dm.user_status === '탈퇴' + {dm.not_mine_user_status === '정지' || + dm.not_mine_user_status === '탈퇴' ? '(알수없음)' : dm.not_mine_nickname}
{dm.recent_message}
- {dm.recent_message_date === '2020-01-01T00:00:00' - ? '' - : parseDate(dm.recent_message_date)} + {dm.recent_message === null ? '' : parseDate(dm.recent_message_date)}
diff --git a/frontend/sweet-red-beans/src/components/DMPage/DMPage.js b/frontend/sweet-red-beans/src/components/DMPage/DMPage.js index b124ef6..cbf0221 100644 --- a/frontend/sweet-red-beans/src/components/DMPage/DMPage.js +++ b/frontend/sweet-red-beans/src/components/DMPage/DMPage.js @@ -8,19 +8,48 @@ import style from '../../css/DMPage/DMPage.module.css'; import { SELECTED_DM } from '../../actions/types'; const DMPage = () => { + const [DMlist, setDMList] = useState([]); const selectedRoomId = useSelector((s) => { if (s === undefined) { return null; } else { - return s.selectedRoom; + if (s.selectedRoom !== undefined) { + return s.selectedRoom; + } else if (s.DMCreate !== undefined) { + return s.DMCreate; + } else { + return null; + } } }); + useEffect(() => { + //DM 목록 조회 + axios + .get('http://localhost:8080/direct-message', { + withCredentials: true, + }) + .then((response) => { + setDMList(response.data.room_id); + }) + .catch((error) => {}); + + return () => { + setDMList(null); + }; + }, []); + + console.log(selectedRoomId); + + useEffect(() => { + console.log(selectedRoomId); + }, [selectedRoomId]); + return ( <>
- +
diff --git a/frontend/sweet-red-beans/src/components/TransactionPage/TransactionDetail.js b/frontend/sweet-red-beans/src/components/TransactionPage/TransactionDetail.js index 2a723b0..5081978 100644 --- a/frontend/sweet-red-beans/src/components/TransactionPage/TransactionDetail.js +++ b/frontend/sweet-red-beans/src/components/TransactionPage/TransactionDetail.js @@ -100,6 +100,10 @@ const TransactionDetail = ({ transaction }) => { alert('정지되거나 탈퇴한 사용자입니다.'); return; } + if (status === '마감') { + alert('이미 마감되었습니다.'); + return; + } const body = { transaction_id: transaction.transaction_id, }; @@ -109,9 +113,10 @@ const TransactionDetail = ({ transaction }) => { }) .then((response) => { dispatch({ - type: SELECTED_DM, + type: DM_CREATE, DMCreate: response.data, }); + console.log(response.data); navigation('/DM'); return; }) @@ -290,11 +295,7 @@ const TransactionDetail = ({ transaction }) => { ) : (
- {status === '진행중' ? ( - - ) : ( - - )} + {likeStatus ? (