forked from PoolC/Haribo
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #89 from PoolC/dev
내가 쓴 글 페이지
- Loading branch information
Showing
9 changed files
with
216 additions
and
3 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
21 changes: 21 additions & 0 deletions
21
apps/web-client/src/components/@business/BusinessErrorBoundary.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,21 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
|
||
export default class BusinessErrorBoundary extends React.Component<PropsWithChildren> { | ||
state = { hasError: false }; | ||
|
||
static getDerivedStateFromError(error: Error) { | ||
return { hasError: true }; | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
return ( | ||
<div style={{ padding: '20px' }}> | ||
<h1>에러가 발생했습니다. 잠시 후 다시 시도해주세요.</h1> | ||
</div> | ||
); | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
apps/web-client/src/components/my-page/MyPageMyPostsEntry.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,133 @@ | ||
import { CommentOutlined } from '@ant-design/icons'; | ||
import { Space, Typography, Avatar, Empty, Pagination } from 'antd'; | ||
import { createStyles } from 'antd-style'; | ||
import Table, { ColumnsType } from 'antd/es/table'; | ||
import dayjs from 'dayjs'; | ||
import { stringify } from 'qs'; | ||
import { Link, useHistory } from 'react-router-dom'; | ||
import { MENU } from '~/constants/menus'; | ||
import { useSearchParams } from '~/hooks/useSearchParams'; | ||
import { PostControllerService, PostResponse, queryKey, useAppSuspenseQuery } from '~/lib/api-v2'; | ||
import getFileUrl from '~/lib/utils/getFileUrl'; | ||
import { getInnerTextFromMarkdown } from '~/lib/utils/getInnerTextFromMarkdown'; | ||
|
||
const useStyles = createStyles(({ css }) => ({ | ||
metaInfoArea: css` | ||
width: 100%; | ||
justify-content: space-between; | ||
`, | ||
search: css` | ||
max-width: 300px; | ||
`, | ||
link: css` | ||
display: block; | ||
width: 100%; | ||
`, | ||
topArea: css` | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: center; | ||
`, | ||
wrapper: css` | ||
display: flex; | ||
align-items: stretch; | ||
flex-direction: column; | ||
gap: 8px; | ||
`, | ||
paginationWrap: css` | ||
display: flex; | ||
justify-content: center; | ||
margin-top: 10px; | ||
`, | ||
commentWrap: css` | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
`, | ||
avatar: css` | ||
width: 40px; | ||
height: 40px; | ||
`, | ||
badge: css` | ||
width: 35px; | ||
height: 35px; | ||
border: 1px solid #47be9b; | ||
`, | ||
clamp: css` | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
-webkit-line-clamp: 1; | ||
overflow: hidden; | ||
`, | ||
fullWidth: css` | ||
width: 100%; | ||
`, | ||
})); | ||
|
||
export default function MyPageMyPostsEntry() { | ||
const { styles } = useStyles(); | ||
|
||
const searchParams = useSearchParams(); | ||
const page = Number(searchParams.get('page') ?? 1); | ||
|
||
const { | ||
data: { posts, maxPage }, | ||
} = useAppSuspenseQuery({ | ||
queryKey: queryKey.post.myPosts(page - 1), | ||
queryFn: () => PostControllerService.viewMyPostsUsingGet({ page: page - 1 }), | ||
}); | ||
|
||
const filteredList = (posts ?? []).filter(Boolean); | ||
|
||
const history = useHistory(); | ||
|
||
const onPageChange = (page: number) => | ||
history.push( | ||
`/${MENU.MY_PAGE_MY_POSTS}?${stringify({ | ||
page, | ||
})}`, | ||
); | ||
|
||
const columns: ColumnsType<PostResponse> = [ | ||
{ | ||
render: (_, post) => ( | ||
<Link to={`/${MENU.BOARD}/${post.postId}`} className={styles.link}> | ||
<Space direction={'vertical'} className={styles.fullWidth} size={'middle'}> | ||
<Space className={styles.metaInfoArea} size={'middle'}> | ||
<Space> | ||
<Typography.Text>{post.writerName}</Typography.Text> | ||
{post.badge && <Avatar src={getFileUrl(post.badge?.imageUrl)} className={styles.badge} />} | ||
</Space> | ||
<Space size={'middle'}> | ||
<Typography.Text type={'secondary'}>{dayjs(post.createdAt).format('YYYY. MM. DD')}</Typography.Text> | ||
<div className={styles.commentWrap}> | ||
<CommentOutlined /> | ||
{post.commentCount ?? 0} | ||
</div> | ||
</Space> | ||
</Space> | ||
<Space direction={'vertical'} size={0}> | ||
<Typography.Title level={5}>{post.title}</Typography.Title> | ||
{post?.body && <Typography.Text className={styles.clamp}>{getInnerTextFromMarkdown(post.body)}</Typography.Text>} | ||
</Space> | ||
</Space> | ||
</Link> | ||
), | ||
}, | ||
]; | ||
|
||
return ( | ||
<div className={styles.fullWidth}> | ||
{filteredList.length === 0 ? ( | ||
<Empty /> | ||
) : ( | ||
<> | ||
<Table dataSource={filteredList} columns={columns} showHeader={false} pagination={false} rowKey={'postId'} /> | ||
<div className={styles.paginationWrap}> | ||
<Pagination current={page} total={maxPage ? maxPage * 10 : 0} showSizeChanger={false} onChange={onPageChange} /> | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} |
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
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,52 @@ | ||
import { Space, Typography } from 'antd'; | ||
import { createStyles } from 'antd-style'; | ||
import { Suspense } from 'react'; | ||
import Skeleton from '~/components/common/Skeleton'; | ||
import MyPageMyPostsEntry from '~/components/my-page/MyPageMyPostsEntry'; | ||
import { Block, WhiteBlock } from '~/styles/common/Block.styles'; | ||
|
||
const useStyles = createStyles(({ css }) => ({ | ||
whiteBlock: css` | ||
&.scope { | ||
padding: 30px 0; | ||
} | ||
`, | ||
wrapper: css` | ||
width: 100%; | ||
max-width: 1200px; | ||
padding: 0 20px; | ||
box-sizing: border-box; | ||
`, | ||
heading: css` | ||
font-size: 18px; | ||
`, | ||
paragraph: css` | ||
font-size: 14px; | ||
color: #666; | ||
`, | ||
fullWidth: css` | ||
width: 100%; | ||
`, | ||
})); | ||
|
||
export default function MyPageMyPostsPage() { | ||
const { styles, cx } = useStyles(); | ||
|
||
return ( | ||
<Block> | ||
<WhiteBlock className={cx(styles.whiteBlock, 'scope')}> | ||
<div className={styles.wrapper}> | ||
<Space direction="vertical" size="large" className={styles.fullWidth}> | ||
<Space direction="vertical" size="middle"> | ||
<h2 className={styles.heading}>내가 쓴 글</h2> | ||
<p className={styles.paragraph}>내가 쓴 글 목록입니다.</p> | ||
</Space> | ||
<Suspense fallback={<Skeleton />}> | ||
<MyPageMyPostsEntry /> | ||
</Suspense> | ||
</Space> | ||
</div> | ||
</WhiteBlock> | ||
</Block> | ||
); | ||
} |