diff --git a/src/components/A/ATopicCard.tsx b/src/components/A/ATopicCard.tsx index 25c245d..804a58c 100644 --- a/src/components/A/ATopicCard.tsx +++ b/src/components/A/ATopicCard.tsx @@ -14,47 +14,50 @@ import { colors } from '@styles/theme'; import { getDateDiff } from '@utils/date'; -interface AlphaTopicCardProps extends TopicResponse { - chip?: 'popular' | 'close'; +interface AlphaTopicCardProps { + topic: TopicResponse; onVote: (topicId: number, side: 'CHOICE_A' | 'CHOICE_B') => void; + chip?: 'popular' | 'close'; } -const AlphaTopicCard = React.memo((props: AlphaTopicCardProps) => { +const AlphaTopicCard = React.memo(({ topic, onVote, chip }: AlphaTopicCardProps) => { const { BottomSheet: CommentSheet, toggleSheet } = useBottomSheet({}); - const [A, B] = props.choices; + const [A, B] = topic.choices; + const roundedPercentageA = Math.round((A.voteCount / topic.voteCount) * 100); + const roundedPercentageB = 100 - roundedPercentageA; const handleCommentChipClick = () => { toggleSheet(); }; const handleVote = (side: 'CHOICE_A' | 'CHOICE_B') => { - props.onVote(props.topicId, side); + onVote(topic.topicId, side); }; return ( <> - {props.chip && ( + {chip && ( )} - {props.topicTitle} + {topic.topicTitle} handleVote('CHOICE_A')} left={() => ( @@ -63,14 +66,14 @@ const AlphaTopicCard = React.memo((props: AlphaTopicCardProps) => { )} /> handleVote('CHOICE_B')} left={() => ( @@ -81,13 +84,13 @@ const AlphaTopicCard = React.memo((props: AlphaTopicCardProps) => { - {getDateDiff(props.createdAt)} 전 + {getDateDiff(topic.createdAt)} 전 - + - + ); diff --git a/src/components/commons/ProgressBar/ProgressBar.tsx b/src/components/commons/ProgressBar/ProgressBar.tsx index 04b62bf..ebfb8d8 100644 --- a/src/components/commons/ProgressBar/ProgressBar.tsx +++ b/src/components/commons/ProgressBar/ProgressBar.tsx @@ -34,9 +34,9 @@ const ProgressBar = ({ style={{ zIndex: 20, width: 'unset' }} > {left && left()} - + {title} - + {revealed && ( <> @@ -76,3 +76,12 @@ const PercentageBar = styled.div<{ percentage: number; highlighted: boolean }>` transition: 0.2s; transition-timing-function: ease-in-out; `; + +const Content = styled(Text)` + display: -webkit-box; + height: 100%; + overflow: hidden; + word-wrap: break-word; + -webkit-line-clamp: 1; + -webkit-box-orient: vertical; +`; diff --git a/src/routes/A/ATopics.tsx b/src/routes/A/ATopics.tsx index bcada4d..394dc6e 100644 --- a/src/routes/A/ATopics.tsx +++ b/src/routes/A/ATopics.tsx @@ -6,12 +6,15 @@ import ATopicCard from '@components/A/ATopicCard'; import { Col, Row } from '@components/commons/Flex/Flex'; import Layout from '@components/commons/Layout/Layout'; import Text from '@components/commons/Text/Text'; +import { Toast } from '@components/commons/Toast/Toast'; import ToggleSwitch from '@components/commons/ToggleSwitch/ToggleSwitch'; import { colors } from '@styles/theme'; import { ALogoIcon, UpDownChevronIcon } from '@icons/index'; +import { ResponseError } from '@apis/fetch'; + import { Container } from './ATopics.styles'; const ATopics = () => { @@ -27,12 +30,18 @@ const ATopics = () => { setTopicFilter(e.target.value); }; - const handleVote = (topicId: number, side: 'CHOICE_A' | 'CHOICE_B') => { - voteMutation.mutate({ - topicId: topicId, - choiceOption: side, - votedAt: new Date().getTime() / 1000, - }); + const handleVote = async (topicId: number, side: 'CHOICE_A' | 'CHOICE_B') => { + try { + await voteMutation.mutateAsync({ + topicId: topicId, + choiceOption: side, + votedAt: new Date().getTime() / 1000, + }); + } catch (error) { + if (error instanceof ResponseError && error.errorData.abCode === 'VOTED_BY_AUTHOR') { + Toast.error('토픽을 작성한 사람은 투표할 수 없어요'); + } + } }; return ( @@ -83,24 +92,7 @@ const ATopics = () => { {topics?.map((topic) => { - return ( - - ); + return ; })}