Skip to content

Commit 8eea49e

Browse files
committed
feat: VoteBlock 컴포넌트 소켓 이벤트에 블럭 id 추가
- 기능 블럭들의 소켓 이벤트 플로우 조정 이후 ee 적용 예정 - 컴포넌트와 템플릿 VoteBlock 디렉토리로 이동
1 parent 56cb8dc commit 8eea49e

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

client/src/components/common/Templates/VoteBlock/index.tsx renamed to client/src/components/Block/VoteBlock/VoteBlockTemplate.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function VoteBlockTemplate({
6767
setOptions(validOptions);
6868
setVoteMode(VoteMode.REGISTERED);
6969

70-
socket.emit(BLOCK_EVENT.CREATE_VOTE, validOptions);
70+
socket.emit(BLOCK_EVENT.CREATE_VOTE, id, validOptions);
7171

7272
toast('투표 등록 완료 ^^', { type: 'info' });
7373
};
@@ -87,7 +87,7 @@ function VoteBlockTemplate({
8787
};
8888

8989
const onEnd = () => {
90-
socket.emit(BLOCK_EVENT.END_VOTE);
90+
socket.emit(BLOCK_EVENT.END_VOTE, id);
9191
};
9292

9393
const onChange: ChangeEventHandler<HTMLInputElement> = ({ target }) => {
@@ -109,20 +109,23 @@ function VoteBlockTemplate({
109109

110110
setSelectedOptionId(targetId);
111111

112-
socket.emit(BLOCK_EVENT.UPDATE_VOTE, targetId, user?.id);
112+
socket.emit(BLOCK_EVENT.UPDATE_VOTE, id, targetId, user?.id);
113113
};
114114

115115
useEffect(() => {
116-
socket.on(BLOCK_EVENT.UPDATE_VOTE, (participantCount) => {
116+
socket.on(`${BLOCK_EVENT.UPDATE_VOTE}-${id}`, (participantCount) => {
117117
setParticipantCount(participantCount);
118118
});
119119

120-
socket.on(BLOCK_EVENT.END_VOTE, ({ options, participantCount }) => {
121-
setVoteMode(VoteMode.END);
122-
setOptions(options);
123-
setParticipantCount(participantCount);
124-
toast('투표가 종료되었어요 ^^');
125-
});
120+
socket.on(
121+
`${BLOCK_EVENT.END_VOTE}-${id}`,
122+
({ options, participantCount }) => {
123+
setVoteMode(VoteMode.END);
124+
setOptions(options);
125+
setParticipantCount(participantCount);
126+
toast('투표가 종료되었어요 ^^');
127+
},
128+
);
126129

127130
return () => {
128131
socket.off(BLOCK_EVENT.UPDATE_VOTE);

client/src/components/Block/VoteBlock.tsx renamed to client/src/components/Block/VoteBlock/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { BLOCK_EVENT } from '@wabinar/constants/socket-message';
22
import { useState, useEffect } from 'react';
3-
import VoteBlockTemplate from 'src/components/common/Templates/VoteBlock';
43
import { VoteMode } from 'src/constants/block';
54
import useSocketContext from 'src/hooks/useSocketContext';
65
import { Option } from 'src/types/block';
76

7+
import VoteBlockTemplate from './VoteBlockTemplate';
8+
89
interface VoteBlockProps {
910
id: string;
1011
}
@@ -17,7 +18,7 @@ function VoteBlock({ id }: VoteBlockProps) {
1718
const [options, setOptions] = useState<Option[]>(initialOption);
1819

1920
useEffect(() => {
20-
socket.on(BLOCK_EVENT.CREATE_VOTE, (options) => {
21+
socket.on(`${BLOCK_EVENT.CREATE_VOTE}-${id}`, (options) => {
2122
setVoteMode(VoteMode.REGISTERED as VoteMode);
2223
setOptions(options);
2324
});

0 commit comments

Comments
 (0)