Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] 방 접속 이벤트 roomPage 컴포넌트가 담당하도록 수정 #302

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_API_URL="https://codeclash.site"
REACT_APP_API_URL="http://localhost:3000"
12 changes: 1 addition & 11 deletions frontend/src/components/lobby/CreateRoomModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,10 @@ const CreateRoomModal: React.FC<CreateRoomModalProps> = ({ closeModal }) => {
createRoomInput.current.capacity = value;
};

const handleEnterRoomEvent = ({ status, message }: { status: string; message: string }) => {
if (status === "error") {
alert(message);
navigate("/lobby");
}
if (status === "success") {
navigate("/room");
}
};

const handleRoomCreated = ({ status, roomId }: ICreateRoomResponse) => {
if (status === "success") {
setRoomId(roomId);
socket?.emit("enter_room", { roomId }, handleEnterRoomEvent);
navigate("/room");
}
};

Expand Down
12 changes: 0 additions & 12 deletions frontend/src/components/lobby/InviteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,11 @@ const InviteModal: React.FC<InviteModalProps> = ({ closeModal }) => {
const navigate = useNavigate();
const { inviteList, setRemoveInvite } = useLobbyStore();
const { setRoomId } = useRoomStore();
const { socket } = useSocketStore();

const handleEnterRoomEvent = ({ status, message }: { status: string; message: string }) => {
if (status === "error") {
alert(message);
navigate("/lobby");
}
if (status === "success") {
navigate("/room");
}
};

const handleAccept = (roomId: string) => {
setRoomId(roomId);
setRemoveInvite(roomId);
closeModal();
socket?.emit("enter_room", { roomId }, handleEnterRoomEvent);
navigate("/room");
};

Expand Down
13 changes: 1 addition & 12 deletions frontend/src/components/lobby/RoomListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,10 @@ const LobbyRoomListBox: React.FC = () => {
const navigate = useNavigate();
const { setRoomId } = useRoomStore();
const { gameRoomList } = useLobbyStore();
const { socket } = useSocketStore();

const handleEnterRoomEvent = ({ status, message }: { status: string; message: string }) => {
if (status === "error") {
alert(message);
navigate("/lobby");
}
if (status === "success") {
navigate("/room");
}
};

const handleEnterRoom = (roomId: string) => {
setRoomId(roomId);
socket?.emit("enter_room", { roomId }, handleEnterRoomEvent);
navigate("/room");
};

const compareState = (a: GameRoom, b: GameRoom) => {
Expand Down
10 changes: 2 additions & 8 deletions frontend/src/pages/RoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const RoomPage: React.FC = () => {
};

const handleEnterRoom = ({ status, message }: { status: string; message: string }) => {
if (status === "fail") {
if (status === "error") {
alert(message);
navigate("/lobby");
}
Expand All @@ -72,13 +72,7 @@ const RoomPage: React.FC = () => {

useEffect(() => {
if (socket) {
socket.emit("room_info", { roomId }, ({ status, roomId, userList, roomName, capacity }: ICreateRoomResponse) => {
if (status === "error") {
alert("방 정보를 불러오는데 실패했습니다.");
navigate("/lobby");
}
setRoomInfo({ roomId, roomName, capacity, isStart: false, userList, problemList: [] });
});
socket.emit("enter_room", { roomId }, handleEnterRoom);
socket.on("user_enter_room", handleUserEnterRoom);
socket.on("user_exit_room", handleUserExitRoom);
socket.on("ready", handleUserReady);
Expand Down
Loading