Skip to content

Commit 2bbf6c8

Browse files
juyeong-sse030
andauthored
Feat/#289-S : 투표 결과 UI에 보여주기 (#292)
* feat : 투표 결과 텍스트로 보여주기 * feat : 투표 블록 결과 시각화 UI - 브라우저 100% 비율로 보는 걸 추천드려요 ..^^ * feat : 투표 결과 퍼센트 소수점 2자리까지만 표시 Co-authored-by: Seyoung Kim <[email protected]>
1 parent 2e3c0e0 commit 2bbf6c8

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

client/src/components/common/Templates/VoteBlock/index.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import useSelectedMom from 'src/hooks/useSelectedMom';
1010
import useSocketContext from 'src/hooks/useSocketContext';
1111
import { useUserContext } from 'src/hooks/useUserContext';
1212
import { Option, VoteMode } from 'src/types/block';
13+
import color from 'styles/color.module.scss';
1314

1415
import style from './style.module.scss';
1516

@@ -119,7 +120,7 @@ function VoteBlockTemplate({
119120
socket.on(BLOCK_EVENT.END_VOTE, ({ options, participantCount }) => {
120121
setVoteMode('end');
121122
setOptions(options);
122-
setParticipantCount(participantCount);
123+
setParticipantCount(Number(participantCount));
123124
toast('투표가 종료되었어요 ^^');
124125
});
125126

@@ -129,6 +130,14 @@ function VoteBlockTemplate({
129130
};
130131
}, [setParticipantCount]);
131132

133+
const getPercent = (count: number) => {
134+
return (count / participantCount) * 100;
135+
};
136+
137+
const getVoteResultText = (count: number) => {
138+
return `(${count}/${participantCount}) ${getPercent(count).toFixed(2)}%`;
139+
};
140+
132141
return (
133142
<div className={style['vote-container']}>
134143
<h3 className={style.title}>투표</h3>
@@ -139,7 +148,7 @@ function VoteBlockTemplate({
139148
)}
140149

141150
<ul>
142-
{options.map(({ id, text }, index) => (
151+
{options.map(({ id, text, count }, index) => (
143152
<li
144153
className={cx('option-item', {
145154
'selected-item':
@@ -148,11 +157,21 @@ function VoteBlockTemplate({
148157
key={id}
149158
onClick={() => onSelect(id)}
150159
>
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+
151170
<div className={style['box-fill']}>{index + 1}</div>
152171
<input
153172
type="text"
154173
className={cx('option-input', {
155-
selected: isRegisteredMode,
174+
'cursor-enable': !isCreateMode,
156175
})}
157176
placeholder="항목을 입력해주세요"
158177
onChange={onChange}
@@ -167,6 +186,11 @@ function VoteBlockTemplate({
167186
onClick={() => onDelete(id)}
168187
/>
169188
)}
189+
{isEndMode && (
190+
<div className={style['vote-result-text']}>
191+
{getVoteResultText(count)}
192+
</div>
193+
)}
170194
</li>
171195
))}
172196
</ul>

client/src/components/common/Templates/VoteBlock/style.module.scss

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,68 @@
2323
.option-item {
2424
display: flex;
2525
position: relative;
26-
flex-direction: row;
26+
z-index: 1;
2727
align-items: center;
2828

2929
width: 100%;
30+
height: 50px;
3031

3132
margin: 14px 0px;
32-
padding: 12px;
33-
border: 4px solid transparent;
33+
padding: 0;
34+
35+
overflow: hidden;
36+
border: 4px solid initial;
3437

3538
border-radius: 12px;
3639
box-shadow: 1px 1px 6px rgba(0, 0, 0, 0.2);
3740

3841
cursor: pointer;
3942

43+
.vote-result-bar {
44+
position: absolute;
45+
z-index: -1;
46+
height: 50px;
47+
}
48+
4049
.box-fill {
4150
display: flex;
4251
align-items: center;
4352
justify-content: center;
4453

45-
width: 30px;
46-
height: 30px;
54+
min-width: 30px;
55+
min-height: 30px;
4756

4857
margin-right: 12px;
58+
margin-left: 10px;
4959
border-radius: 4px;
5060
background-color: $primary-100;
5161
color: $white;
5262
font-size: 16px;
5363
}
5464

5565
.option-input {
56-
width: 100%;
66+
flex-grow: 1;
5767
background-color: transparent;
5868
}
59-
.selected {
69+
.cursor-enable {
6070
cursor: pointer;
6171
}
6272

6373
.position-right {
6474
position: absolute;
6575
right: 0;
6676
}
77+
78+
.vote-result-text {
79+
margin-right: 10px;
80+
margin-left: auto;
81+
font-size: 12px;
82+
text-align: right;
83+
}
6784
}
6885

6986
.selected-item {
70-
border: 4px solid $highlight-100;
87+
border: 4px solid $highlight-200;
7188
}
7289

7390
.vote-buttons {

0 commit comments

Comments
 (0)