-
Notifications
You must be signed in to change notification settings - Fork 7
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 #221 from feedoong/feature/postItem
Add: FeedItem 및 PostFeedItem 컴포넌트 새롭게 생성
- Loading branch information
Showing
7 changed files
with
162 additions
and
6 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
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
60 changes: 60 additions & 0 deletions
60
apps/next-app/src/features/post/ui/PostFeedItem/PostFeedItem.style.tsx
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,60 @@ | ||
import Image from 'next/image' | ||
import styled from 'styled-components' | ||
|
||
import { ellipsis, getTypographyStyles } from 'styles/fonts' | ||
|
||
export const Container = styled.div` | ||
border-top-right-radius: 32px; | ||
border-top-left-radius: 32px; | ||
border-bottom-right-radius: 32px; | ||
border-bottom-left-radius: 0px; | ||
overflow: hidden; | ||
` | ||
|
||
export const Body = styled.div` | ||
background-color: var(--color-surface-container-lowest); | ||
padding: 20px; | ||
display: flex; | ||
justify-content: space-between; | ||
` | ||
|
||
export const Footer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 12px 20px 16px; | ||
background-color: var(--color-surface-container-lowest); | ||
border-top: 1px solid var(--color-divider); | ||
` | ||
|
||
export const Title = styled.p` | ||
${getTypographyStyles('Headline3_B')}; | ||
${ellipsis(1)}; | ||
color: var(--color-font-primary); | ||
` | ||
|
||
export const Contents = styled.p` | ||
${getTypographyStyles('Body1_M')}; | ||
${ellipsis(2)}; | ||
color: var(--color-font-secondary); | ||
` | ||
|
||
export const Thumbnail = styled.img` | ||
object-fit: cover; | ||
border-radius: 16px; | ||
` | ||
|
||
export const ChannelTitle = styled.p` | ||
cursor: pointer; | ||
${getTypographyStyles('Body2_B')}; | ||
color: var(--color-font-tertiary); | ||
` | ||
|
||
export const SubText = styled.p` | ||
${getTypographyStyles('Body2_M')}; | ||
color: var(--color-font-tertiary); | ||
` | ||
|
||
export const ImageButton = styled(Image)` | ||
cursor: pointer; | ||
` |
94 changes: 94 additions & 0 deletions
94
apps/next-app/src/features/post/ui/PostFeedItem/PostFeedItem.tsx
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,94 @@ | ||
import { useRouter } from 'next/navigation' | ||
|
||
import Anchor from 'components/common/Anchor' | ||
import { | ||
copyToClipboard, | ||
getDiameterByType, | ||
} from 'components/common/FeedItem/FeedItem.utils' | ||
import useReadPost from 'components/common/FeedItem/hooks/useReadPost' | ||
import useToggleLike from 'components/common/FeedItem/hooks/useToggleLike' | ||
import Flex from 'components/common/Flex' | ||
import LogoIcon from 'components/common/LogoIcon' | ||
import type { UserItemDTO } from 'services/types/_generated/apiDocumentation.schemas' | ||
import { getFormatDate, getWellKnownChannelImg } from 'utils' | ||
|
||
import * as S from './PostFeedItem.style' | ||
|
||
import Icons from 'assets/icons' | ||
|
||
interface Props extends UserItemDTO { | ||
isLoggedIn: boolean | ||
} | ||
|
||
export const PostFeedItem = ({ | ||
id, | ||
title, | ||
channelId, | ||
channelImageUrl, | ||
link, | ||
imageUrl, | ||
description, | ||
channelTitle, | ||
publishedAt, | ||
isLiked, | ||
isLoggedIn, | ||
}: Props) => { | ||
const router = useRouter() | ||
const { handleLike } = useToggleLike({ id, isLiked }) | ||
const { handleRead } = useReadPost({ id }) | ||
|
||
const goToChannelPage = (channelId: number) => { | ||
router.push(`/channels/${channelId}`) | ||
} | ||
|
||
return ( | ||
<S.Container> | ||
<S.Body> | ||
<Flex gap={6} direction="column" style={{ marginRight: '20px' }}> | ||
<Anchor href={link} target="_blank" onClick={() => handleRead(id)}> | ||
<S.Title>{title}</S.Title> | ||
</Anchor> | ||
<Anchor href={link} target="_blank" onClick={() => handleRead(id)}> | ||
<S.Contents>{description}</S.Contents> | ||
</Anchor> | ||
</Flex> | ||
{imageUrl && <S.Thumbnail src={imageUrl} width={90} height={90} />} | ||
</S.Body> | ||
|
||
<S.Footer> | ||
<Flex gap={8}> | ||
<LogoIcon | ||
diameter={getDiameterByType('card')} | ||
src={channelImageUrl ?? getWellKnownChannelImg(String(link))} | ||
/> | ||
<S.ChannelTitle onClick={() => goToChannelPage(channelId)}> | ||
{channelTitle} | ||
</S.ChannelTitle> | ||
|
||
<S.SubText>{getFormatDate(publishedAt, 'YYYY.MM.DD')}</S.SubText> | ||
</Flex> | ||
|
||
<Flex gap={8}> | ||
{isLoggedIn && ( | ||
<S.ImageButton | ||
alt="북마크" | ||
src={isLiked ? Icons.Bookmark : Icons.BookmarkDeactive} | ||
width={16} | ||
height={16} | ||
onClick={() => handleLike(String(id))} | ||
priority | ||
/> | ||
)} | ||
<S.ImageButton | ||
alt="링크 복사" | ||
src={Icons.Link} | ||
width={16} | ||
height={16} | ||
onClick={() => copyToClipboard(String(link))} | ||
priority | ||
/> | ||
</Flex> | ||
</S.Footer> | ||
</S.Container> | ||
) | ||
} |
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 @@ | ||
export * from './PostFeedItem' |
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