Skip to content

Commit

Permalink
feat: isDeadPersonPinoco를 통해 제거된 사람의 정체 추정
Browse files Browse the repository at this point in the history
  • Loading branch information
zizonyoungjun committed Nov 28, 2024
1 parent 8f2cdc9 commit ffdade1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
interface IVoteResultPhaseProps {
deadPerson: string | null;
voteResult: Record<string, number>;
isPinoco: boolean;
isDeadPersonPinoco: boolean | null;
}

export default function VoteResult({ deadPerson, voteResult, isPinoco }: IVoteResultPhaseProps) {
export default function VoteResult({
deadPerson,
voteResult,
isDeadPersonPinoco,
}: IVoteResultPhaseProps) {
const maxVotes = Math.max(...Object.values(voteResult));
const maxVotedUsers = Object.entries(voteResult)
.filter(([_, votes]) => votes === maxVotes)
.map(([userId]) => userId);
const totalVotes = Object.values(voteResult).reduce((sum, votes) => sum + votes, 0);

const isTie = maxVotedUsers.length > 1;
const isNoElimination = isTie || maxVotedUsers.includes('');

const getRoleText = (userId: string) => {
return userId === '' ? '' : isPinoco && userId === deadPerson ? '피노코' : '제페토';
const getRoleText = () => {
if (isDeadPersonPinoco === null) return '';
return isDeadPersonPinoco ? '피노코' : '제페토';
};

const renderVoteResults = () => (
Expand All @@ -33,7 +36,7 @@ export default function VoteResult({ deadPerson, voteResult, isPinoco }: IVoteRe
<div className="flex flex-col items-center justify-center w-full h-full space-y-4">
<h2 className="text-2xl font-bold text-white-default">투표 결과</h2>
<p className="text-xl text-white-default">
{deadPerson}님이 제거되었습니다. {deadPerson}님은 {getRoleText(deadPerson)}였습니다!
{deadPerson}님이 제거되었습니다. {deadPerson}님은 {getRoleText()}였습니다!
</p>
{renderVoteResults()}
</div>
Expand Down
5 changes: 4 additions & 1 deletion packages/frontend/src/hooks/useVoteResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useRoomStore } from '@/states/store/roomStore';
interface IVoteResult {
voteResult: Record<string, number>;
deadPerson: string;
isDeadPersonPinoco: boolean;
}

export default function useVoteResult(
Expand All @@ -17,6 +18,7 @@ export default function useVoteResult(
const { removeUser } = useRoomStore();
const [voteResult, setVoteResult] = useState<Record<string, number>>({});
const [deadPerson, setDeadPerson] = useState<string | null>(null);
const [isDeadPersonPinoco, setIsDeadPersonPinoco] = useState<boolean | null>(null); // 추가

useEffect(() => {
if (!socket) return;
Expand All @@ -31,6 +33,7 @@ export default function useVoteResult(

setVoteResult(data.voteResult);
setDeadPerson(data.deadPerson);
setIsDeadPersonPinoco(data.isDeadPersonPinoco); // 추가

if (setSelectedVote) {
setSelectedVote(null);
Expand All @@ -45,5 +48,5 @@ export default function useVoteResult(
};
}, [socket, onIsVotedChange, onPhaseChange, removeUser, setSelectedVote]);

return { voteResult, deadPerson };
return { voteResult, deadPerson, isDeadPersonPinoco }; // 수정
}

0 comments on commit ffdade1

Please sign in to comment.