Skip to content

Commit 55e851f

Browse files
committed
Shows title for Posthead
1 parent e692508 commit 55e851f

File tree

8 files changed

+128
-28
lines changed

8 files changed

+128
-28
lines changed

src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Core from './containers/base/Core';
88
import RegisterPage from './pages/RegisterPage';
99
import { JazzbarProvider } from './lib/jazzbar';
1010
const MainPage = loadable(() => import('./pages/main/MainPage'));
11-
const PostPage = loadable(() => import('./pages/PostPage'));
1211
const EmailLoginPage = loadable(() => import('./pages/EmailLoginPage'));
1312
const WritePage = loadable(() => import('./pages/WritePage'));
1413
const VelogPage = loadable(() => import('./pages/velog/VelogPage'));

src/components/post/PostHead.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 PostHeadBlock = styled(VelogResponsive)`
7+
margin-top: 5.5rem;
8+
h1 {
9+
font-size: 3rem;
10+
line-height: 1.25;
11+
letter-spacing: -0.02rem;
12+
margin-top: 0;
13+
font-weight: 800;
14+
color: ${palette.gray8};
15+
}
16+
`;
17+
18+
export interface PostHeadProps {
19+
title: string;
20+
tags: string[];
21+
username: string;
22+
date: string | number;
23+
}
24+
25+
const PostHead: React.FC<PostHeadProps> = ({ title }) => {
26+
return (
27+
<PostHeadBlock>
28+
<h1>{title}</h1>
29+
</PostHeadBlock>
30+
);
31+
};
32+
33+
export default PostHead;
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 PostHead, { PostHeadProps } from '../PostHead';
4+
5+
describe('PostHead', () => {
6+
const setup = (props: Partial<PostHeadProps> = {}) => {
7+
const initialProps: PostHeadProps = {
8+
title: 'title',
9+
tags: ['tagA', 'tagB'],
10+
username: 'velopert',
11+
date: new Date(Date.now() - 1000 * 60 * 60 * 5),
12+
};
13+
const utils = render(<PostHead {...initialProps} {...props} />);
14+
return {
15+
...utils,
16+
};
17+
};
18+
it('renders title', () => {
19+
const { getByText } = setup();
20+
getByText('title');
21+
});
22+
it('renders tags', () => {});
23+
it('renders username', () => {});
24+
it('renders date', () => {});
25+
});
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+
4+
const VelogResponsiveBlock = styled.div`
5+
width: 768px;
6+
margin: 0 auto;
7+
`;
8+
9+
export interface VelogResponsiveProps {
10+
className?: string;
11+
style?: React.CSSProperties;
12+
}
13+
14+
const VelogResponsive: React.FC<VelogResponsiveProps> = ({
15+
children,
16+
className,
17+
style,
18+
}) => {
19+
return (
20+
<VelogResponsiveBlock
21+
children={children}
22+
className={className}
23+
style={style}
24+
/>
25+
);
26+
};
27+
28+
export default VelogResponsive;

src/containers/post/PostViewer.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import styled from 'styled-components';
33
import { Query, QueryResult } from 'react-apollo';
44
import { READ_POST, SinglePost } from '../../lib/graphql/post';
5+
import PostHead from '../../components/post/PostHead';
56

67
export interface PostViewerProps {
78
username: string;
@@ -17,9 +18,22 @@ const PostViewer: React.FC<PostViewerProps> = ({ username, urlSlug }) => {
1718
url_slug: urlSlug,
1819
}}
1920
>
20-
{(result: QueryResult<{ post: SinglePost }>) => {
21-
console.log(result);
22-
return null;
21+
{({ loading, error, data }: QueryResult<{ post: SinglePost }>) => {
22+
console.log(data);
23+
if (loading) return null; // TODO: show placeholder
24+
if (!data || !data.post) return null;
25+
if (error) return null; // SHOW ERROR
26+
const { post } = data;
27+
return (
28+
<>
29+
<PostHead
30+
title={post.title}
31+
tags={post.tags}
32+
username={username}
33+
date={post.released_at}
34+
/>
35+
</>
36+
);
2337
}}
2438
</Query>
2539
);

src/pages/PostPage.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/pages/velog/PostPage.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
import { RouteComponentProps } from 'react-router';
4+
import PostViewer from '../../containers/post/PostViewer';
5+
6+
const PostPageBlock = styled.div``;
7+
8+
export interface PostPageProps
9+
extends RouteComponentProps<{
10+
username: string;
11+
urlSlug: string;
12+
}> {}
13+
14+
const PostPage: React.FC<PostPageProps> = ({ match }) => {
15+
const { username, urlSlug } = match.params;
16+
return <PostViewer username={username} urlSlug={urlSlug} />;
17+
};
18+
19+
export default PostPage;

src/pages/velog/VelogPage.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import * as React from 'react';
22
import VelogPageTemplate from '../../components/velog/VelogPageTemplate';
3-
import { RouteComponentProps } from 'react-router';
3+
import { RouteComponentProps, Route } from 'react-router';
44
import ConfigLoader from '../../containers/velog/ConfigLoader';
5+
import PostViewer from '../../containers/post/PostViewer';
6+
import PostPage from './PostPage';
57

68
export interface VelogPageProps
79
extends RouteComponentProps<{
810
username: string;
911
}> {}
1012

1113
const VelogPage: React.FC<VelogPageProps> = ({ match }) => {
14+
const { username } = match.params;
1215
return (
1316
<VelogPageTemplate>
14-
<ConfigLoader username={match.params.username} />
17+
<ConfigLoader username={username} />
18+
<Route path="/@:username/:urlSlug" component={PostPage} />
1519
</VelogPageTemplate>
1620
);
1721
};

0 commit comments

Comments
 (0)