오늘까지 반영사항은 깃허브 finalProject에 merge함
스크럼회의(14:00)
디자이너 전체회의(19:30)
⇒ 조건부 렌더링으로 length > 0일 때 보이게 하고 아닐 때(채팅방이 정상적이지 않을 때) 아예 null 처리를 해주는 방식으로 설정***```javascript
(chatList.jsx)
// 채팅방 list
<Div onClick={(e) => e.stopPropagation()}>
{Room !== undefined &&
Room !== [] &&
Room.map((item, i) => {
return (
<div key={i}>
{item.chatList.length > 0 ? (<>
// 조건이 0보다 커야만, 즉 채팅이 있어야만 채팅방이 개설되는 로직
<RoomList onClick={() => onClickChatting(item)}>
<Profile>
<div><img src={item.postUserAvatarUrl} style={{ width: 44, height: 44, borderRadius:"50%"}}/></div>
<div>
<div>{item.postUserNickname} <Time>{item.chatList[item.chatList.length-1].sendDate}</Time></div>
<Message>
{item.chatList[item.chatList.length-1].message}
// 스몰 이슈:
{/* 대화의 맨 마지막만 가지고 오는 로직이면 위와 같이 진행하면 됨 */}
</Message>
</div>
</Profile>
<SellImg>
{item.image !== undefined && (
<>
<img src={item.image.imgUrl} style={{ width: 44, height: 44}} />
</>)}
</SellImg>
</RoomList>
</>): null}
</div>
);
})}
</Div>
=> 전역에 먹히는 font.css를 만든 다음 적용해주고 안 먹히는 버튼 같은 경우는 inline style로 적용했다.
(Apis.js)
// 채팅
CreateRoomAX: (payload) => token.post(`/api/chat/room`, payload),
GetRoomListAX: () => token.get(`/api/chat/roomList`),
GetInitialChatListAX: (payload) => token.post(`/api/chat/roomInfo`, payload),
// 위에서 토큰 관련 코드를 모두 선언해준 다음 아래서는 이와 같이 메소드와 경로를 설정해준다.
(ChattingSlice.js)
// 방만드는 코드
export const __CreateRoom = createAsyncThunk(
"/chat/__CreateRoom",
async (payload, thunkAPI) => {
try {
// const response = await axios.post(`${process.env.REACT_APP_SERVER}/api/chat/room`, payload.postId,
const response = await Apis.CreateRoomAX(
payload);
return thunkAPI.fulfillWithValue(response.data);
} catch (error) {
return thunkAPI.rejectWithValue(error.response.data);
}
}
);
// 방리스트
export const __getRoomList = createAsyncThunk(
"/chat/__getRoomList",
async (payload, thunkAPI) => {
try {
const response = await Apis.GetRoomListAX();
return thunkAPI.fulfillWithValue(response.data);
} catch (error) {
return thunkAPI.rejectWithValue(error.response.data);
}
}
);
// 메인 채팅 화면
export const __getinitialChatList = createAsyncThunk(
"/chat/__getInitialChatList",
async (payload, thunkAPI) => {
try {
const response = await Apis.GetInitialChatListAX(payload);
return thunkAPI.fulfillWithValue(response.data);
} catch (error) {
return thunkAPI.rejectWithValue(error.response.data);
}
}
);
slice Thunk 부분이 한결 더 가벼워진다.