Skip to content

Commit 56b014b

Browse files
committed
fix : currentRoom 제거
#8
1 parent d619980 commit 56b014b

File tree

6 files changed

+13
-54
lines changed

6 files changed

+13
-54
lines changed

frontend/app/_components/Header.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useParams } from 'next/navigation';
22
import { useContext, useEffect, useState } from 'react';
33
import { HeaderStyled, LogoImage } from '../(root)/_related/root.styled';
4-
import { useGetRoomStatusFirebaseRoomRoomIdGet } from '../api/room/hooks/useQueryRoom';
54
import { HeaderLogoTitle } from '../home/_related/home.styled';
65
import { ChatContext } from '../room/[roomId]/_related/ChatProvider';
76
import Button from './Button';
@@ -11,9 +10,6 @@ type Props = {
1110
};
1211
const PigHeader = ({ onClick }: Props) => {
1312
const { roomId } = useParams<{ roomId: string }>();
14-
const { data: currentRoom } = useGetRoomStatusFirebaseRoomRoomIdGet({
15-
roomId,
16-
});
1713
const { background, gameInfo, roomInfo } = useContext(ChatContext);
1814
const [timer, setTimer] = useState(0);
1915

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
import { QUERY_KEY } from '@/constant';
22
import { useQuery } from '@tanstack/react-query';
3-
import {
4-
getAllRoomsFirebaseRoomGet,
5-
getRoomStatusFirebaseRoomRoomIdGet,
6-
} from '../room.api';
7-
import { ApiGetRoomStatusFirebaseRoomRommIdGetParams } from '../types';
3+
import { getAllRoomsFirebaseRoomGet } from '../room.api';
84

95
export function useGetAllRoomsFirebaseRoomGet() {
106
return useQuery({
117
queryKey: [QUERY_KEY.GET_ALL_ROOMS],
128
queryFn: () => getAllRoomsFirebaseRoomGet(),
139
});
1410
}
15-
16-
export function useGetRoomStatusFirebaseRoomRoomIdGet({
17-
roomId,
18-
isConnecting,
19-
}: ApiGetRoomStatusFirebaseRoomRommIdGetParams & { isConnecting?: boolean }) {
20-
return useQuery({
21-
queryKey: [QUERY_KEY.GET_ROOM_STATUS, roomId, isConnecting],
22-
queryFn: () => getRoomStatusFirebaseRoomRoomIdGet({ roomId }),
23-
enabled: !!roomId,
24-
});
25-
}

frontend/app/api/room/room.api.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
import { apiClient } from '@/types/apiClient';
22
import {
33
ApiEndGameFirebaseRoomRoomIdEndPutParams,
4-
ApiGetRoomStatusFirebaseRoomRommIdGetParams,
54
ApiStartGameFirebaseRoomIdStartPutParams,
65
} from './types';
76

8-
export async function getRoomStatusFirebaseRoomRoomIdGet({
9-
roomId,
10-
}: ApiGetRoomStatusFirebaseRoomRommIdGetParams) {
11-
if (!roomId) return;
12-
const response =
13-
await apiClient.firebase.getRoomStatusFirebaseRoomRoomIdGet(roomId);
14-
return response.data;
15-
}
16-
177
export async function getAllRoomsFirebaseRoomGet() {
188
const response = await apiClient.firebase.getAllRoomsFirebaseRoomGet();
199
return response.data;

frontend/app/room/[roomId]/_related/ChatProvider.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use client';
22

3-
import { useGetRoomStatusFirebaseRoomRoomIdGet } from '@/app/api/room/hooks/useQueryRoom';
43
import { GlobalContext } from '@/app/GlobalContext';
54
import {
65
ALERT,
@@ -89,14 +88,9 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
8988
const [background, setBackground] =
9089
useState<ChatContextType['background']>(null);
9190
const [votedId, setVotedId] = useState<string | null>(null);
92-
const { data: currentRoom } = useGetRoomStatusFirebaseRoomRoomIdGet({
93-
roomId,
94-
isConnecting,
95-
});
9691
const [currentUserList, setCurrentUserList] = useState<User[]>([]);
9792
const [roomInfo, setRoomInfo] = useState<RoomModel | null>(null);
9893
const [gameInfo, setGameInfo] = useState<GameInfoMessage | null>(null);
99-
const isGameStarted = currentRoom?.RoomState;
10094

10195
const handleClearGame = () => {
10296
setCanSpeak(true);
@@ -116,9 +110,6 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
116110

117111
useEffect(() => {
118112
// 게임이 시작 되지 않은 상태(대기실)면, 말할 수 있음
119-
if (!isGameStarted) {
120-
setCanSpeak(true);
121-
}
122113

123114
if (!roomId || !userId || isConnecting || wsRef.current) return;
124115

@@ -130,6 +121,8 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
130121
return;
131122
}
132123

124+
console.log(roomName);
125+
133126
wsRef.current = new WebSocket(
134127
// `ws://localhost:8000/ws/room/${roomId}/${userId}/${roomName}`
135128
`wss://wam-coin.store/ws/room/${roomId}/${userId}/${roomName}`
@@ -239,7 +232,7 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
239232
}
240233
setIsConnecting(false);
241234
};
242-
}, [roomId, userId, isConnecting, currentRoom]);
235+
}, [roomId, userId, isConnecting]);
243236

244237
const handleChangeUserMemo: ChatContextType['handleChangeUserMemo'] = (
245238
userID

frontend/app/room/[roomId]/_sections/MyChat.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useGetRoomStatusFirebaseRoomRoomIdGet } from '@/app/api/room/hooks/useQueryRoom';
2-
import { useParams } from 'next/navigation';
1+
import { useContext } from 'react';
2+
import { ChatContext } from '../_related/ChatProvider';
33
import {
44
ChatContent,
55
ChatImage,
@@ -10,12 +10,9 @@ import {
1010
import { ChatMessage } from '../_related/type';
1111

1212
const MyChat = ({ message }: { message: ChatMessage }) => {
13-
const { roomId } = useParams<{ roomId: string }>();
14-
const { data: currentRoom } = useGetRoomStatusFirebaseRoomRoomIdGet({
15-
roomId,
16-
});
13+
const { roomInfo } = useContext(ChatContext);
1714

18-
const user = currentRoom?.UserList?.find(
15+
const user = roomInfo?.UserList?.find(
1916
(user) => user.UserID === message.userID
2017
);
2118

frontend/app/room/[roomId]/_sections/OtherUserChat.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useGetRoomStatusFirebaseRoomRoomIdGet } from '@/app/api/room/hooks/useQueryRoom';
2-
import { useParams } from 'next/navigation';
1+
import { useContext } from 'react';
2+
import { ChatContext } from '../_related/ChatProvider';
33
import {
44
ChatContent,
55
ChatImage,
@@ -10,11 +10,9 @@ import {
1010
import { ChatMessage } from '../_related/type';
1111

1212
const OtherUserChat = ({ message }: { message: ChatMessage }) => {
13-
const { roomId } = useParams<{ roomId: string }>();
14-
const { data: currentRoom } = useGetRoomStatusFirebaseRoomRoomIdGet({
15-
roomId,
16-
});
17-
const user = currentRoom?.UserList?.find(
13+
const { roomInfo } = useContext(ChatContext);
14+
15+
const user = roomInfo?.UserList?.find(
1816
(user) => user.UserID === message.userID
1917
);
2018

0 commit comments

Comments
 (0)