Skip to content

Commit

Permalink
mash-up-kr#2 heart state 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
godjoy committed Mar 26, 2021
1 parent 12161ec commit 69be1af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/answerlist/AnswerItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import React, { useState } from 'react'
import * as Styled from './AnswerItem.Styled'
import { Answer, AnswerListProps } from 'types/Answer'
import heart from './../../assets/heart.svg'
import redheart from './../../assets/heart.svg'
import grayheart from './../../assets/grayheart.svg'

interface AnswerItemProps {
answer: any
}

function AnswerItem({ answer }: AnswerItemProps) {
const [like, setLike] = useState<number>(answer.likeNum)
const addLike = () => setLike(like + 1)
const [likeNum, setLikeNum] = useState(answer.likeNum)
const [like, setLike] = useState(answer.like)
const [heart, setHeart] = useState(answer.like ? redheart : grayheart)

const addLike = () => {
setLikeNum(like ? likeNum - 1 : likeNum + 1)
setLike(!like)
setHeart(like ? grayheart : redheart)
console.log(like)
}

return (
<Styled.AnswerArea>
Expand All @@ -18,8 +27,8 @@ function AnswerItem({ answer }: AnswerItemProps) {
<Styled.AnswerInfoBlock>
<div className="time">{answer.time}</div>
<div className="likeButton" onClick={addLike}>
<img src={heart} alt="heart icon" />
{like}
<img src={heart} alt="heart icon" onClick={addLike} />
{likeNum}
</div>
</Styled.AnswerInfoBlock>
</Styled.AnswerArea>
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Concern.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const dummy: Answer[] = [
contents:
'남자친구와 만난지 3년이 되어갑니다. 그런데 며칠전 남자친구의 휴대폰을 우연히 보게 되었어요...',
time: '2010.02.12 오전 08:00',
like: true,
likeNum: 10,
},
{
Expand All @@ -28,6 +29,7 @@ const dummy: Answer[] = [
contents:
'남자친구와 만난지 3년이 되어갑니다. 그런데 며칠전 남자친구의 휴대폰을 우연히 보게 되었어요...',
time: '2010.02.12 오전 08:01',
like: false,
likeNum: 20,
},
{
Expand All @@ -36,6 +38,7 @@ const dummy: Answer[] = [
contents:
'남자친구와 만난지 3년이 되어갑니다. 그런데 며칠전 남자친구의 휴대폰을 우연히 보게 되었어요...',
time: '2010.02.12 오전 08:01',
like: false,
likeNum: 20,
},
{
Expand All @@ -44,6 +47,7 @@ const dummy: Answer[] = [
contents:
'남자친구와 만난지 3년이 되어갑니다. 그런데 며칠전 남자친구의 휴대폰을 우연히 보게 되었어요...',
time: '2010.02.12 오전 08:01',
like: true,
likeNum: 20,
},
]
1 change: 1 addition & 0 deletions src/types/Answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export interface Answer {
name: string
contents: string
time: string
like: boolean
likeNum: number
}

0 comments on commit 69be1af

Please sign in to comment.