Skip to content

Commit

Permalink
feat: 투표 진행 사항 메세지 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjinan096 committed Jul 2, 2024
1 parent 9121006 commit 4996798
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/app/_components/PostItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface PostItemProps {
isNickname?: boolean;
}

const convertOptionsToString = (options: string[]) => {
const generateVoteStatus = (options: string[], isTerminated: boolean) => {
const result = [] as string[];
let remainingCount = 0;

Expand All @@ -22,10 +22,16 @@ const convertOptionsToString = (options: string[]) => {
result.push(option);
}

if (remainingCount > 0)
return `${result.join(',')}${remainingCount}투표 진행 중`;
const optionString = result.join(', ');
let suffix = remainingCount > 0 ? `${remainingCount}` : ' ';

return `${result.join(',')} 투표 진행 중`;
if (isTerminated) {
suffix += '투표 종료';
} else {
suffix += '투표 진행 중';
}

return optionString + suffix;
};

const PostItem = ({ post, isNickname = true }: PostItemProps) => {
Expand Down Expand Up @@ -64,7 +70,7 @@ const PostItem = ({ post, isNickname = true }: PostItemProps) => {
size={16}
className={cn(!isTerminated && 'text-primary')}
/>
<span className='font-text-1-rg'>{`${isTerminated ? '투표 종료' : convertOptionsToString(onGoingVote)}`}</span>
<span className='font-text-1-rg'>{`${generateVoteStatus(onGoingVote, isTerminated)}`}</span>
</div>
<div className='flex items-center gap-4'>
<span className='font-text-3-rg flex items-center gap-2'>
Expand Down

0 comments on commit 4996798

Please sign in to comment.