Skip to content

Commit 1a4f788

Browse files
committed
Loads post
1 parent 478a839 commit 1a4f788

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed

src/components/post/PostTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const PostTemplateBlock = styled(PageTemplate)``;
66

77
interface PostTemplateProps {}
88

9-
const PostTemplate: React.SFC<PostTemplateProps> = props => {
10-
return <PostTemplateBlock>포스트임</PostTemplateBlock>;
9+
const PostTemplate: React.SFC<PostTemplateProps> = ({ children }) => {
10+
return <PostTemplateBlock>{children}</PostTemplateBlock>;
1111
};
1212

1313
export default PostTemplate;

src/containers/post/PostViewer.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
import { Query, QueryResult } from 'react-apollo';
4+
import { READ_POST, SinglePost } from '../../lib/graphql/post';
5+
6+
export interface PostViewerProps {
7+
username: string;
8+
urlSlug: string;
9+
}
10+
11+
const PostViewer: React.FC<PostViewerProps> = ({ username, urlSlug }) => {
12+
return (
13+
<Query
14+
query={READ_POST}
15+
variables={{
16+
username,
17+
url_slug: urlSlug,
18+
}}
19+
>
20+
{(result: QueryResult<{ post: SinglePost }>) => {
21+
console.log(result);
22+
return null;
23+
}}
24+
</Query>
25+
);
26+
};
27+
28+
export default PostViewer;

src/lib/graphql/post.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,33 @@ export type PartialPost = {
3737
comments_count: number;
3838
};
3939

40+
// Generated by https://quicktype.io
41+
42+
export interface SinglePost {
43+
id: string;
44+
title: string;
45+
released_at: string;
46+
updated_at: string;
47+
tags: string[];
48+
body: string;
49+
is_markdown: boolean;
50+
is_private: boolean;
51+
is_temp: boolean;
52+
user: {
53+
username: string;
54+
profile: {
55+
display_name: string;
56+
thumbnail: string;
57+
short_bio: string;
58+
};
59+
velog_config: {
60+
title: string;
61+
};
62+
};
63+
}
64+
4065
export const GET_POST_LIST = gql`
41-
query Post($cursor: ID) {
66+
query Posts($cursor: ID) {
4267
posts(cursor: $cursor) {
4368
id
4469
title
@@ -60,6 +85,33 @@ export const GET_POST_LIST = gql`
6085
}
6186
`;
6287

88+
export const READ_POST = gql`
89+
query ReadPost($username: String, $url_slug: String) {
90+
post(username: $username, url_slug: $url_slug) {
91+
id
92+
title
93+
released_at
94+
updated_at
95+
tags
96+
body
97+
is_markdown
98+
is_private
99+
is_temp
100+
user {
101+
username
102+
profile {
103+
display_name
104+
thumbnail
105+
short_bio
106+
}
107+
velog_config {
108+
title
109+
}
110+
}
111+
}
112+
}
113+
`;
114+
63115
export const WRITE_POST = gql`
64116
mutation WritePost(
65117
$title: String

src/pages/PostPage.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import * as React from 'react';
2+
import { RouteComponentProps } from 'react-router-dom';
23
import PostTemplate from '../components/post/PostTemplate';
4+
import PostViewer from '../containers/post/PostViewer';
35

4-
interface PostPageProps {}
6+
interface PostPageProps
7+
extends RouteComponentProps<{
8+
username: string;
9+
urlSlug: string;
10+
}> {}
511

6-
const PostPage: React.SFC<PostPageProps> = () => {
7-
return <PostTemplate />;
12+
const PostPage: React.SFC<PostPageProps> = ({ match }) => {
13+
const { username, urlSlug } = match.params;
14+
15+
return (
16+
<PostTemplate>
17+
<PostViewer username={username} urlSlug={urlSlug} />
18+
</PostTemplate>
19+
);
820
};
921

1022
export default PostPage;

0 commit comments

Comments
 (0)