Skip to content

Commit

Permalink
Merge pull request #138 from KakaoTech-BootCamp-Team-2/dev
Browse files Browse the repository at this point in the history
🚀 fix:채팅최종최종수정
  • Loading branch information
Hanjuri authored Sep 10, 2024
2 parents 6cd25f1 + 1caa95e commit ee6a60f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/jsLinters/eslint.xml

This file was deleted.

18 changes: 4 additions & 14 deletions src/pages/chat/ChatMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,13 @@ function ChatMain() {
const [chatList, setChatList] = useState([])
const [selectedChatRoom, setSelectedChatRoom] = useState(null);

const getUsernameFromCookieOrLocalStorage = () => {
// 쿠키에서 username 값을 먼저 확인
const usernameFromCookie = document.cookie
.split("; ")
.find((row) => row.startsWith("username="))
?.split("=")[1];

// 쿠키에 값이 없으면 localStorage에서 가져오기
if (usernameFromCookie) {
return usernameFromCookie;
} else {
return localStorage.getItem("username");
}
const getUsername = () => {
const usernameFromLocalStorage = localStorage.getItem('username');
return usernameFromLocalStorage || "kakao_3691500201";
};
const nowUser = getUsernameFromCookieOrLocalStorage();
console.log('cookie-get:', nowUser);

const nowUser = getUsername();

useEffect(() => {
console.log(nowUser,'현재 사용자')
Expand Down
12 changes: 10 additions & 2 deletions src/pages/chat/ChatRoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ const ChatRoom = (props) => {
const { uuid, name } = props;
const [messages, setMessages] = useState([]);
const [message, setMessage] = useState("");
const currentUsername = localStorage.getItem('username'); // 현재 사용자 설정

// 현재 사용자 이름 설정 함수
const getUsername = () => {
const usernameFromLocalStorage = localStorage.getItem('username');
return usernameFromLocalStorage || "kakao_3691500201";
};

const currentUsername = getUsername(); // 현재 사용자 이름 설정
const roomId = uuid;
const [stompClient, setStompClient] = useState(null); // STOMP 클라이언트 객체 저장

Expand Down Expand Up @@ -88,11 +95,12 @@ const ChatRoom = (props) => {
message: message,
};

// 서버로 메시지 발행 (전송)
stompClient.send("/pub/messages", {}, JSON.stringify(chatMessage));

console.log("전송된 메시지:", chatMessage);

setMessage("");
setMessage(""); // 입력창 초기화
};

return (
Expand Down

0 comments on commit ee6a60f

Please sign in to comment.