-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #686 from woowacourse-teams/feat/668-template-like
템플릿 좋아요 기능 구현
- Loading branch information
Showing
28 changed files
with
516 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { HttpResponse } from 'msw'; | ||
|
||
import { END_POINTS } from '@/routes'; | ||
import { LikeDeleteRequest, LikePostRequest } from '@/types'; | ||
|
||
import { customFetch } from './customFetch'; | ||
|
||
const API_URL = process.env.REACT_APP_API_URL; | ||
|
||
export const LIKE_API_URL = `${API_URL}${END_POINTS.LIKES}`; | ||
|
||
export const postLike = async ({ templateId }: LikePostRequest) => { | ||
const response = await customFetch<HttpResponse>({ | ||
method: 'POST', | ||
url: `${LIKE_API_URL}/${templateId}`, | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
export const deleteLike = async ({ templateId }: LikeDeleteRequest) => { | ||
const response = await customFetch<HttpResponse>({ | ||
method: 'DELETE', | ||
url: `${LIKE_API_URL}/${templateId}`, | ||
}); | ||
|
||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { theme } from '../../style/theme'; | ||
|
||
type State = 'like' | 'unlike' | 'unClickable'; | ||
|
||
interface Props { | ||
state: State; | ||
size: number; | ||
} | ||
|
||
const LikeIcon = ({ state, size }: Props) => { | ||
const fillColor = { | ||
like: theme.color.light.analogous_primary_400, | ||
unlike: 'none', | ||
unClickable: theme.color.light.secondary_800, | ||
}[state]; | ||
|
||
const strokeColor = { | ||
like: theme.color.light.analogous_primary_400, | ||
unlike: theme.color.light.secondary_800, | ||
unClickable: theme.color.light.secondary_800, | ||
}[state]; | ||
|
||
return ( | ||
<svg width={size} height={size} viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'> | ||
<path | ||
d='M20.42 4.58045C19.9183 4.07702 19.3222 3.67758 18.6658 3.40503C18.0094 3.13248 17.3057 2.99219 16.595 2.99219C15.8842 2.99219 15.1805 3.13248 14.5241 3.40503C13.8678 3.67758 13.2716 4.07702 12.77 4.58045L12 5.36045L11.23 4.58045C10.7283 4.07702 10.1322 3.67758 9.47578 3.40503C8.81941 3.13248 8.11568 2.99219 7.40496 2.99219C6.69425 2.99219 5.99052 3.13248 5.33414 3.40503C4.67776 3.67758 4.08164 4.07702 3.57996 4.58045C1.45996 6.70045 1.32996 10.2804 3.99996 13.0004L12 21.0004L20 13.0004C22.67 10.2804 22.54 6.70045 20.42 4.58045Z' | ||
fill={fillColor} | ||
stroke={strokeColor} | ||
strokeWidth='1' | ||
strokeLinecap='round' | ||
strokeLinejoin='round' | ||
/> | ||
</svg> | ||
); | ||
}; | ||
|
||
export default LikeIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import { theme } from '@/style/theme'; | ||
|
||
export const LikeButtonContainer = styled.button<{ isLiked: boolean }>` | ||
cursor: pointer; | ||
display: flex; | ||
gap: 0.5rem; | ||
align-items: center; | ||
justify-content: center; | ||
height: 2.5rem; | ||
padding: 0 0.75rem; | ||
color: ${({ isLiked }) => (isLiked ? theme.color.light.analogous_primary_400 : 'white')}; | ||
border: 1px solid | ||
${({ isLiked }) => (isLiked ? theme.color.light.analogous_primary_400 : theme.color.light.secondary_800)}; | ||
border-radius: 16px; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { LikeIcon } from '@/assets/images'; | ||
import { Text } from '@/components'; | ||
import { theme } from '@/style/theme'; | ||
import { formatWithK } from '@/utils'; | ||
|
||
import * as S from './LikeButton.style'; | ||
|
||
interface Props { | ||
likesCount: number; | ||
isLiked: boolean; | ||
onLikeButtonClick: () => void; | ||
} | ||
|
||
const LikeButton = ({ likesCount, isLiked, onLikeButtonClick }: Props) => ( | ||
<S.LikeButtonContainer isLiked={isLiked} onClick={onLikeButtonClick}> | ||
<LikeIcon state={isLiked ? 'like' : 'unlike'} size={20} /> | ||
<Text.Medium color={theme.color.light.secondary_800}>{formatWithK(likesCount)}</Text.Medium> | ||
</S.LikeButtonContainer> | ||
); | ||
|
||
export default LikeButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export const LikeCounterContainer = styled.div` | ||
display: flex; | ||
gap: 0.75rem; | ||
align-items: center; | ||
height: 1.5rem; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { LikeIcon } from '@/assets/images'; | ||
import { Text } from '@/components'; | ||
import { theme } from '@/style/theme'; | ||
import { formatWithK } from '@/utils'; | ||
|
||
import * as S from './LikeCounter.style'; | ||
|
||
interface Props { | ||
likesCount: number; | ||
isLiked: boolean; | ||
} | ||
|
||
const LikeCounter = ({ likesCount, isLiked }: Props) => ( | ||
<S.LikeCounterContainer> | ||
<LikeIcon state={isLiked ? 'like' : 'unClickable'} size={14} /> | ||
<Text.Small color={theme.color.light.secondary_800}>{formatWithK(likesCount)}</Text.Small> | ||
</S.LikeCounterContainer> | ||
); | ||
|
||
export default LikeCounter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.