Skip to content

Commit 3a0c535

Browse files
committed
Initialize PostComments related components
1 parent ad5a45f commit 3a0c535

File tree

8 files changed

+166
-0
lines changed

8 files changed

+166
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
import VelogResponsive from '../velog/VelogResponsive';
4+
import palette from '../../lib/styles/palette';
5+
6+
const PostCommentsTemplateBlock = styled(VelogResponsive)`
7+
margin-top: 7.5rem;
8+
color: ${palette.gray8};
9+
h4 {
10+
font-size: 1.125rem;
11+
line-height: 1.5;
12+
font-weight: 600;
13+
margin-bottom: 1rem;
14+
}
15+
`;
16+
17+
const Contents = styled.div``;
18+
19+
export interface PostCommentsTemplateProps {
20+
count: number;
21+
}
22+
23+
const PostCommentsTemplate: React.FC<PostCommentsTemplateProps> = ({
24+
count,
25+
children,
26+
}) => {
27+
return (
28+
<PostCommentsTemplateBlock>
29+
<h4>{count}개의 댓글</h4>
30+
<Contents>{children}</Contents>
31+
</PostCommentsTemplateBlock>
32+
);
33+
};
34+
35+
export default PostCommentsTemplate;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
import TextareaAutosize from 'react-textarea-autosize';
4+
import Button from '../common/Button';
5+
6+
const PostCommentsWriteBlock = styled.div`
7+
> .buttons-wrapper {
8+
display: flex;
9+
justify-content: flex-end;
10+
}
11+
`;
12+
const StyledTextarea = styled(TextareaAutosize)``;
13+
14+
export interface PostCommentsWriteProps {}
15+
16+
const PostCommentsWrite: React.FC<PostCommentsWriteProps> = props => {
17+
return (
18+
<PostCommentsWriteBlock>
19+
<StyledTextarea placeholder="댓글을 작성하세요" />
20+
<div className="buttons-wrapper">
21+
<Button>댓글 작성</Button>
22+
</div>
23+
</PostCommentsWriteBlock>
24+
);
25+
};
26+
27+
export default PostCommentsWrite;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react';
2+
import { render } from 'react-testing-library';
3+
import PostCommentsTemplate, {
4+
PostCommentsTemplateProps,
5+
} from '../PostCommentsTemplate';
6+
7+
describe('PostCommentsTemplate', () => {
8+
const setup = (props: Partial<PostCommentsTemplateProps> = {}) => {
9+
const initialProps: PostCommentsTemplateProps = {
10+
count: 9,
11+
};
12+
const utils = render(
13+
<PostCommentsTemplate {...initialProps} {...props}>
14+
contents
15+
</PostCommentsTemplate>,
16+
);
17+
return {
18+
...utils,
19+
};
20+
};
21+
it('shows comments count and children', () => {
22+
const { getByText } = setup();
23+
getByText('9개의 댓글');
24+
getByText('contents');
25+
});
26+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from 'react';
2+
import { render } from 'react-testing-library';
3+
import PostCommentsWrite, {
4+
PostCommentsWriteProps,
5+
} from '../PostCommentsWrite';
6+
7+
describe('PostCommentsWrite', () => {
8+
const setup = (props: Partial<PostCommentsWriteProps> = {}) => {
9+
const initialProps: PostCommentsWriteProps = {};
10+
const utils = render(<PostCommentsWrite {...initialProps} {...props} />);
11+
12+
const textarea = utils.getByPlaceholderText('댓글을 작성하세요');
13+
const writeButton = utils.getByText('댓글 작성');
14+
return {
15+
textarea,
16+
writeButton,
17+
...utils,
18+
};
19+
};
20+
it('renders textarea and a button', () => {
21+
const { textarea, writeButton } = setup();
22+
expect(textarea).toBeVisible();
23+
expect(writeButton).toBeVisible();
24+
});
25+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from 'react';
2+
import { render } from 'react-testing-library';
3+
import PostCommentsWrite, {
4+
PostCommentsWriteProps,
5+
} from '../PostCommentsWrite';
6+
7+
describe('PostCommentsWrite', () => {
8+
const setup = (props: Partial<PostCommentsWriteProps> = {}) => {
9+
const initialProps: PostCommentsWriteProps = {};
10+
const utils = render(<PostCommentsWrite {...initialProps} {...props} />);
11+
12+
const textarea = utils.getByPlaceholderText('댓글을 작성하세요');
13+
const writeButton = utils.getByText('댓글 작성');
14+
return {
15+
textarea,
16+
writeButton,
17+
...utils,
18+
};
19+
};
20+
it('renders textarea and a button', () => {
21+
const { textarea, writeButton } = setup();
22+
expect(textarea).toBeVisible();
23+
expect(writeButton).toBeVisible();
24+
});
25+
});

src/containers/post/PostComments.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react';
2+
import PostCommentsTemplate from '../../components/post/PostCommentsTemplate';
3+
import PostCommentsWriteContainer from './PostCommentsWriteContainer';
4+
5+
export interface PostCommentsProps {}
6+
7+
const PostComments: React.FC<PostCommentsProps> = props => {
8+
return (
9+
<PostCommentsTemplate count={9}>
10+
<PostCommentsWriteContainer />
11+
</PostCommentsTemplate>
12+
);
13+
};
14+
15+
export default PostComments;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as React from 'react';
2+
import PostCommentsWrite from '../../components/post/PostCommentsWrite';
3+
export interface PostCommentWriteContainerProps {}
4+
5+
const PostCommentsWriteContainer: React.FC<
6+
PostCommentWriteContainerProps
7+
> = props => {
8+
return <PostCommentsWrite />;
9+
};
10+
11+
export default PostCommentsWriteContainer;

src/containers/post/PostViewer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Query, QueryResult } from 'react-apollo';
33
import { READ_POST, SinglePost } from '../../lib/graphql/post';
44
import PostHead from '../../components/post/PostHead';
55
import PostContent from '../../components/post/PostContent';
6+
import PostComments from './PostComments';
67

78
export interface PostViewerProps {
89
username: string;
@@ -39,6 +40,7 @@ const PostViewer: React.FC<PostViewerProps> = ({ username, urlSlug }) => {
3940
}
4041
/>
4142
<PostContent isMarkdown={post.is_markdown} body={post.body} />
43+
<PostComments />
4244
</>
4345
);
4446
}}

0 commit comments

Comments
 (0)