Skip to content

Commit 89cd876

Browse files
committed
2 parents b19d445 + 5da3a38 commit 89cd876

File tree

4 files changed

+5
-53
lines changed

4 files changed

+5
-53
lines changed

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ interface ChatContextType {
3737
handleLeaveRoom: () => Promise<void>;
3838
canSpeak: boolean;
3939
canVote: boolean;
40-
subject: string | null;
4140
isLiar: boolean;
42-
currentUserList: User[];
43-
handleChangeUserMemo: (userID: string) => void;
4441
handleVote: (userID: string) => void;
4542
handleKill: (userID: string) => void;
4643
votedId: string | null;
@@ -60,10 +57,7 @@ export const ChatContext = createContext<ChatContextType>({
6057
handleLeaveRoom: async () => {},
6158
canSpeak: false,
6259
canVote: false,
63-
subject: null,
6460
isLiar: false,
65-
currentUserList: [],
66-
handleChangeUserMemo: () => {},
6761
votedId: null,
6862
handleVote: () => {},
6963
handleKill: () => {},
@@ -83,12 +77,10 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
8377
const [canSpeak, setCanSpeak] = useState(false);
8478
const [canVote, setCanVote] = useState(false);
8579
const [canKill, setCanKill] = useState(false);
86-
const [subject, setSubject] = useState<string | null>(null);
8780
const [isLiar, setIsLiar] = useState<boolean>(false);
8881
const [background, setBackground] =
8982
useState<ChatContextType['background']>(null);
9083
const [votedId, setVotedId] = useState<string | null>(null);
91-
const [currentUserList, setCurrentUserList] = useState<User[]>([]);
9284
const [roomInfo, setRoomInfo] = useState<RoomModel | null>(null);
9385
const [gameInfo, setGameInfo] = useState<GameInfoMessage | null>(null);
9486

@@ -100,12 +92,8 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
10092
setCanKill(false);
10193
setBackground(null);
10294
setIsLiar(false);
103-
setSubject(null);
10495
setGameInfo(null);
10596
setRoomInfo(null);
106-
setCurrentUserList((prevUser) =>
107-
prevUser?.map((user) => ({ ...user, memo: 'pig' }))
108-
);
10997
};
11098

11199
useEffect(() => {
@@ -157,32 +145,12 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
157145
setMessages((prev: Message[]) => [...(prev ?? []), message]);
158146
} else if (message.type === ROOM_INFO) {
159147
setRoomInfo(message.room);
160-
const updatedUserList = message?.room?.UserList?.map((newUser) => {
161-
// 현재 유저 리스트에 이 유저가 있는지 확인
162-
const existingUser = currentUserList.find(
163-
(user) => user.UserID === newUser.UserID
164-
);
165-
166-
// 유저가 있으면 그대로 반환
167-
if (existingUser) {
168-
return existingUser;
169-
}
170-
171-
// 없다면 'pig'의 역할로 추가
172-
return {
173-
...newUser,
174-
memo: 'pig' as 'pig',
175-
};
176-
});
177-
178-
setCurrentUserList(updatedUserList ?? []);
179148
} else if (message.type === GAME_INFO) {
180149
setGameInfo(message);
181150
} else if (message.type === STATE) {
182151
setCanSpeak(message.speak);
183152
} else if (message.type === ROLE) {
184153
setIsLiar(message.role === 'wolf');
185-
setSubject(message.word);
186154
} else if (message.type === PROCESS) {
187155
setVotedId(null);
188156
if (message.state === 'start') {
@@ -239,18 +207,6 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
239207
};
240208
}, [roomId, userId, isConnecting]);
241209

242-
const handleChangeUserMemo: ChatContextType['handleChangeUserMemo'] = (
243-
userID
244-
) => {
245-
setCurrentUserList((prev) =>
246-
prev.map((user) =>
247-
user.UserID === userID
248-
? { ...user, memo: user.memo === 'pig' ? 'wolf' : 'pig' }
249-
: user
250-
)
251-
);
252-
};
253-
254210
const handleLeaveRoom = async () => {
255211
if (!userId) {
256212
enqueueSnackbar({ variant: 'error', message: '유저 정보가 없습니다.' });
@@ -326,12 +282,9 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
326282
messages,
327283
sendMessage,
328284
handleLeaveRoom,
329-
handleChangeUserMemo,
330285
canSpeak,
331286
canVote,
332-
subject,
333287
isLiar,
334-
currentUserList,
335288
votedId,
336289
canKill,
337290
handleVote,
@@ -345,9 +298,7 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
345298
canSpeak,
346299
canVote,
347300
canKill,
348-
subject,
349301
isLiar,
350-
currentUserList,
351302
handleVote,
352303
handleKill,
353304
background,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import MyChat from './MyChat';
1313
import OtherUserChat from './OtherUserChat';
1414

1515
const Chatting = () => {
16-
const { messages, subject } = useContext(ChatContext);
16+
const { messages, gameInfo } = useContext(ChatContext);
1717
const { userId: myId } = useContext(GlobalContext);
1818
const messagesEndRef = useRef<HTMLDivElement>(null);
19+
const isMeLiar = gameInfo?.wolf === myId;
20+
const subject = isMeLiar ? gameInfo?.wolfSubject : gameInfo?.pigSubject;
1921

2022
// 새로운 메시지가 추가되면 스크롤을 최신 메시지로 이동
2123
useEffect(() => {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212

1313
export const UserComponent = ({ user }: { user: User }) => {
1414
const {
15-
handleChangeUserMemo,
1615
isLiar,
1716
canVote,
1817
votedId,
@@ -36,7 +35,6 @@ export const UserComponent = ({ user }: { user: User }) => {
3635
<UserImage src={'/died.jpeg'} />
3736
) : (
3837
<UserImage
39-
onClick={() => handleChangeUserMemo(user.UserID)}
4038
src={(isLiar && isMe) || isWolf ? '/wolf.png' : '/pig.webp'}
4139
/>
4240
)}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { RoomTitle, UserCard, UserImage } from '../_related/session.styled';
66
import { UserComponent } from './UserComponent';
77

88
const Users = () => {
9-
const { currentUserList, roomInfo } = useContext(ChatContext);
9+
const { roomInfo } = useContext(ChatContext);
1010
const MAX_USERS = 8;
1111
const USERS_PER_ROW = 4;
12+
const currentUserList = roomInfo?.UserList ?? [];
1213

1314
const remainingSlots = MAX_USERS - currentUserList.length;
1415
const allSlots: User[] = [

0 commit comments

Comments
 (0)