@@ -30,8 +30,9 @@ function VoteBlockTemplate({
3030 options,
3131 setOptions,
3232} : VoteBlockProps ) {
33- const [ isCreateMode , isRegisteredMode , isEndMode ] = [
33+ const [ isCreateMode , isRegisteringMode , isRegisteredMode , isEndMode ] = [
3434 mode === VoteMode . CREATE ,
35+ mode === VoteMode . REGISTERING ,
3536 mode === VoteMode . REGISTERED ,
3637 mode === VoteMode . END ,
3738 ] ;
@@ -67,7 +68,7 @@ function VoteBlockTemplate({
6768 setOptions ( validOptions ) ;
6869 setVoteMode ( VoteMode . REGISTERED ) ;
6970
70- socket . emit ( BLOCK_EVENT . CREATE_VOTE , validOptions ) ;
71+ socket . emit ( BLOCK_EVENT . REGISTER_VOTE , id , validOptions ) ;
7172
7273 toast ( '투표 등록 완료 ^^' , { type : 'info' } ) ;
7374 } ;
@@ -87,7 +88,7 @@ function VoteBlockTemplate({
8788 } ;
8889
8990 const onEnd = ( ) => {
90- socket . emit ( BLOCK_EVENT . END_VOTE ) ;
91+ socket . emit ( BLOCK_EVENT . END_VOTE , id ) ;
9192 } ;
9293
9394 const onChange : ChangeEventHandler < HTMLInputElement > = ( { target } ) => {
@@ -109,20 +110,23 @@ function VoteBlockTemplate({
109110
110111 setSelectedOptionId ( targetId ) ;
111112
112- socket . emit ( BLOCK_EVENT . UPDATE_VOTE , targetId , user ?. id ) ;
113+ socket . emit ( BLOCK_EVENT . UPDATE_VOTE , id , targetId , user ?. id ) ;
113114 } ;
114115
115116 useEffect ( ( ) => {
116- socket . on ( BLOCK_EVENT . UPDATE_VOTE , ( participantCount ) => {
117+ socket . on ( ` ${ BLOCK_EVENT . UPDATE_VOTE } - ${ id } ` , ( participantCount ) => {
117118 setParticipantCount ( participantCount ) ;
118119 } ) ;
119120
120- socket . on ( BLOCK_EVENT . END_VOTE , ( { options, participantCount } ) => {
121- setVoteMode ( VoteMode . END ) ;
122- setOptions ( options ) ;
123- setParticipantCount ( participantCount ) ;
124- toast ( '투표가 종료되었어요 ^^' ) ;
125- } ) ;
121+ socket . on (
122+ `${ BLOCK_EVENT . END_VOTE } -${ id } ` ,
123+ ( { options, participantCount } ) => {
124+ setVoteMode ( VoteMode . END ) ;
125+ setOptions ( options ) ;
126+ setParticipantCount ( participantCount ) ;
127+ toast ( '투표가 종료되었어요 ^^' ) ;
128+ } ,
129+ ) ;
126130
127131 return ( ) => {
128132 socket . off ( BLOCK_EVENT . UPDATE_VOTE ) ;
@@ -140,63 +144,70 @@ function VoteBlockTemplate({
140144
141145 return (
142146 < div className = { style [ 'vote-container' ] } >
143- < h3 className = { style . title } > 투표 </ h3 >
147+ < h3 className = { style . title } > { '투표' } </ h3 >
144148 { ( isRegisteredMode || isEndMode ) && (
145149 < span className = { style [ 'participant-cnt' ] } >
146150 { participantCount } 명 참여
147151 </ span >
148152 ) }
149-
150- < ul >
151- { options . map ( ( { id, text, count } , index ) => (
152- < li
153- className = { cx ( 'option-item' , {
154- 'selected-item' :
155- ( isRegisteredMode || isEndMode ) && id === selectedOptionId ,
156- } ) }
157- key = { id }
158- onClick = { ( ) => onSelect ( id ) }
159- >
160- { isEndMode && (
161- < div
162- className = { style [ 'vote-result-bar' ] }
163- style = { {
164- width : `${ getPercent ( count ) } %` ,
165- backgroundColor : color . highlight100 ,
166- } }
167- > </ div >
168- ) }
169-
170- < div className = { style [ 'box-fill' ] } > { index + 1 } </ div >
171- < input
172- type = "text"
173- className = { cx ( 'option-input' , {
174- selected : isRegisteredMode ,
175- } ) }
176- placeholder = "항목을 입력해주세요"
177- onChange = { onChange }
178- data-id = { id }
179- readOnly = { isRegisteredMode || isEndMode }
180- defaultValue = { text }
181- />
182- { isCreateMode && (
183- < Button
184- icon = { < BiX size = "20" color = "white" /> }
185- ariaLabel = "항목 삭제"
186- onClick = { ( ) => onDelete ( id ) }
187- />
188- ) }
189- { isEndMode && (
190- < div className = { style [ 'vote-result-text' ] } >
191- { getVoteResultText ( count ) }
192- </ div >
193- ) }
194- </ li >
195- ) ) }
196- </ ul >
197-
153+ {
154+ < ul >
155+ { isCreateMode ? (
156+ < li className = { style [ 'option-item' ] } >
157+ < div className = { style [ 'box-fill' ] } > { '^^' } </ div >
158+ < div > 등록될 때까지 기다려주세요</ div >
159+ </ li >
160+ ) : (
161+ options . map ( ( { id, text, count } , index ) => (
162+ < li
163+ className = { cx ( 'option-item' , {
164+ 'selected-item' :
165+ ( isRegisteredMode || isEndMode ) && id === selectedOptionId ,
166+ } ) }
167+ key = { id }
168+ onClick = { ( ) => onSelect ( id ) }
169+ >
170+ { isEndMode && (
171+ < div
172+ className = { style [ 'vote-result-bar' ] }
173+ style = { {
174+ width : `${ getPercent ( count ) } %` ,
175+ backgroundColor : color . highlight100 ,
176+ } }
177+ > </ div >
178+ ) }
179+
180+ < div className = { style [ 'box-fill' ] } > { index + 1 } </ div >
181+ < input
182+ type = "text"
183+ className = { cx ( 'option-input' , {
184+ selected : isRegisteredMode ,
185+ } ) }
186+ placeholder = "항목을 입력해주세요"
187+ onChange = { onChange }
188+ data-id = { id }
189+ readOnly = { isRegisteredMode || isEndMode }
190+ defaultValue = { text }
191+ />
192+ { isRegisteringMode && (
193+ < Button
194+ icon = { < BiX size = "20" color = "white" /> }
195+ ariaLabel = "항목 삭제"
196+ onClick = { ( ) => onDelete ( id ) }
197+ />
198+ ) }
199+ { isEndMode && (
200+ < div className = { style [ 'vote-result-text' ] } >
201+ { getVoteResultText ( count ) }
202+ </ div >
203+ ) }
204+ </ li >
205+ ) )
206+ ) }
207+ </ ul >
208+ }
198209 < div className = { style [ 'vote-buttons' ] } >
199- { isCreateMode && (
210+ { isRegisteringMode && (
200211 < >
201212 < Button onClick = { onAdd } text = "항목 추가" />
202213 < Button onClick = { onRegister } text = "투표 등록" />
0 commit comments